library(WDI)
library(sf)
library(tmap)
library(rnaturalearth)
library(rnaturalearthdata)
library(tidyverse)
library(grid)
library(tidycensus)
library(tidygeocoder)
library(units)

1 Scripting tools: functions and iteration with the tidyverse

country_boundaries<-ne_countries(scale="medium", returnclass="sf") %>% 
                       filter(iso_a3 !="ATA")
tm_shape(country_boundaries)+
  tm_polygons()

trade_gdp_2010_2018<-WDI(country="all", # specifies we want data for all countries available
                                indicator="NE.TRD.GNFS.ZS", # specifies code for desired indicator
                                start=2010, # Start year for data series
                                end=2018, # End year for data series
                                extra=T) # returns
trade_gdp_2015<-
  trade_gdp_2010_2018 %>%  # Establishes object to be modified
  filter(year=="2015") %>% # Subsets observations where the "year" variable equals "2015"
  rename(trade_gdp_2015=NE.TRD.GNFS.ZS)
trade_2015_spatial<-full_join(country_boundaries, trade_gdp_2015,
                                    by=c("iso_a3"="iso3c"))
tm_shape(trade_2015_spatial)+
  tm_polygons(col="trade_gdp_2015",
              n=7,
              style="quantile",
              palette="YlOrBr",
              title="Trade as a % of GDP,\n2015",
              textNA="No Data")+
    tm_layout(legend.outside=T,
              legend.outside.position = "bottom",
              main.title="Crossnational Variation in Commercial Integration, 2015",
              main.title.size=1,
              main.title.position="center",
              inner.margins=c(0.06,0.10,0.10,0.08), # Sets margins to create whitespace
              frame=FALSE,
              attr.outside = TRUE)+ # Places credits section outside map
   tm_credits("Map Author: Aditya Ranganath\nData Source: World Bank\nDevelopment Indicators (WDI)", position=c(0.78,0), size=0.38) # Specifies content, position, size of credits
## Warning: The shape trade_2015_spatial contains empty units.

wdi_map_maker<-function(wdi_variable_code, start_year, end_year, 
                        legend.title, main_map_title){

country_boundaries<-ne_countries(scale="medium", returnclass="sf") %>% 
                       filter(iso_a3 !="ATA")
  
wdi_extract<-WDI(country="all",
              indicator=wdi_variable_code,
              start=start_year,
              end=end_year,
              extra=T)

spatial_object_tomap<-full_join(country_boundaries, wdi_extract,
                                    by=c("iso_a3"="iso3c"))

final_map<-tm_shape(spatial_object_tomap)+
  tm_polygons(col=wdi_variable_code,
              n=7,
              style="quantile",
              palette="YlOrBr",
              title=legend.title,
              textNA="No Data")+
    tm_layout(legend.outside=T,
              legend.outside.position = "bottom",
              main.title=main_map_title,
              main.title.size=1,
              main.title.position="center",
              inner.margins=c(0.06,0.10,0.10,0.08), # Sets margins to create whitespace
              frame=FALSE,
              attr.outside = TRUE)+ # Places credits section outside map
   tm_credits("Map Author: Aditya Ranganath\nData Source: World Bank\nDevelopment Indicators (WDI)", position=c(0.78,0), size=0.38) # Specifies content, position, size of credits
return(final_map)
}
wdi_map_maker(wdi_variable_code="BG.GSR.NFSV.GD.ZS", start_year=2017, end_year=2017, 
                        legend.title="Services Trade (% of GDP)", main_map_title="Service Market Integration, 2017")
## Warning: The shape spatial_object_tomap contains empty units.

wdi_map_maker(wdi_variable_code="GC.TAX.TOTL.GD.ZS", start_year=2017, end_year=2017, 
                        legend.title="Taxes (% of GDP)", main_map_title="Government Taxes as a Share of GDP, 2017")
## Warning: The shape spatial_object_tomap contains empty units.

input_list<-list(wdi_variable_code=c("BG.GSR.NFSV.GD.ZS", "GC.TAX.TOTL.GD.ZS"),
                 start_year=c(2017, 2017),
                 end_year=c(2017, 2017),
                 legend.title=c("Services Trade (% of GDP)", "Taxes (%GDP)"),
                 main_map_title=c("Service Market Integration, 2017", "Government Taxes as a Share of GDP, 2017")) 
map_list<-pmap(input_list, wdi_map_maker)
map_list[[1]]
## Warning: The shape spatial_object_tomap contains empty units.

map_list[[2]]
## Warning: The shape spatial_object_tomap contains empty units.

# Layering Data

https://www.aiddata.org/data/world-bank-geocoded-research-release-level-1-v1-4-2

worldbank_project_locations<-read_csv("https://www.dropbox.com/s/bzmqj2h29ewov9o/worldbank_projects_locations.csv?dl=1")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_character(),
##   precision_code = col_double(),
##   geoname_id = col_double(),
##   latitude = col_double(),
##   longitude = col_double(),
##   location_class = col_double(),
##   geographic_exactness = col_double(),
##   is_geocoded = col_double(),
##   transactions_start_year = col_double(),
##   transactions_end_year = col_double(),
##   total_commitments = col_double(),
##   total_disbursements = col_double()
## )
## ℹ Use `spec()` for the full column specifications.
worldbank_locations_spatial<-st_as_sf(worldbank_project_locations, coords=c("longitude", "latitude"), crs=4326)
tm_shape(worldbank_locations_spatial)+
  tm_dots()

tm_shape(country_boundaries)+
  tm_polygons()+
tm_shape(worldbank_locations_spatial)+
  tm_dots()

## tmap mode set to plotting
worldmap_projects<-
  tm_shape(country_boundaries)+
    tm_polygons("red2")+
  tm_shape(worldbank_locations_spatial)+
    tm_dots("lightblue1")

worldmap_projects

2 Spatial joins

Malawi_constituencies<-st_read("MAA.shp")
## Reading layer `MAA' from data source `/Users/adra7980/Documents/git_repositories/ARSC5040_GIS/class_notes/class2/data/data_malawi/MAA.shp' using driver `ESRI Shapefile'
## Simple feature collection with 246 features and 18 fields
## geometry type:  POLYGON
## dimension:      XY
## bbox:           xmin: 32.67395 ymin: -17.125 xmax: 35.91682 ymax: -9.3675
## geographic CRS: WGS 84
tm_shape(Malawi_constituencies)+
  tm_polygons()

3 Dissolving Data

# extract state population data from 2010 census
usa_state_boundaries<-get_decennial(geography = "state", 
                                     variables = "P001001",
                                     year = 2010,
                                     geometry=TRUE)
# Visualize state polygons
tm_shape(usa_state_boundaries)+
  tm_polygons()

# Remove Alaska, Hawaii, and Puerto Rico so that we only have continental USA
continental_USA<-usa_state_boundaries %>% 
                  filter(GEOID!="02" & GEOID!="15" & GEOID!="72")
# Visualize continental USA polygons
tm_shape(continental_USA)+
  tm_polygons()

# Define regional groups
continental_USA_regions<-continental_USA %>% 
  mutate(region=case_when(
    (GEOID=="09"|GEOID=="23"|GEOID=="25"|GEOID=="33"|GEOID=="44"|
       GEOID=="50")~"New England",
    (GEOID=="10"|GEOID=="11"|GEOID=="24"|GEOID=="34"|
       GEOID=="36"|GEOID=="42")~"Mideast",
    (GEOID=="17"|GEOID=="18"|GEOID=="26"|GEOID=="39"|GEOID=="55")~
      "Great Lakes",
    (GEOID=="19"|GEOID=="20"|GEOID=="27"|GEOID==29|GEOID=="31"|
       GEOID=="38"|GEOID=="46")~"Plains",
    (GEOID=="01"|GEOID=="05"|GEOID=="12"|GEOID=="13"|
       GEOID=="21"|GEOID=="22"|GEOID=="28"|GEOID=="37"|
       GEOID=="45"|GEOID=="47"|GEOID=="51"|GEOID=="54")~"Southeast",
    (GEOID=="04"|GEOID=="35"|GEOID=="40"|GEOID=="48")~"Southwest",
    (GEOID=="08"|GEOID=="16"|GEOID=="30"|GEOID=="49"|
       GEOID=="56")~"Rocky Mountain",
    (GEOID=="06"|GEOID=="32"|GEOID=="41"|GEOID=="53")~"Far West"))
# Project "continental_USA_regions"
continental_USA_regions_projected<-st_transform(continental_USA_regions, 5070)
continental_USA_regions_projected
## Simple feature collection with 49 features and 5 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -2356114 ymin: 272001.7 xmax: 2258200 ymax: 3172568
## projected CRS:  NAD83 / Conus Albers
## # A tibble: 49 × 6
##    GEOID NAME           variable    value                        geometry region
##  * <chr> <chr>          <chr>       <dbl>              <MULTIPOLYGON [m]> <chr> 
##  1 23    Maine          P001001   1328361 (((2217413 2725832, 2217670 27… New E…
##  2 25    Massachusetts  P001001   6547629 (((2057879 2340987, 2058775 23… New E…
##  3 26    Michigan       P001001   9883640 (((548934.7 2812066, 549554.6 … Great…
##  4 30    Montana        P001001    989415 (((-633753 2472318, -648844.1 … Rocky…
##  5 32    Nevada         P001001   2700551 (((-1581791 1701476, -1582641 … Far W…
##  6 34    New Jersey     P001001   8791894 (((1727369 2035186, 1727394 20… Midea…
##  7 36    New York       P001001  19378102 (((1977956 2282780, 1979208 22… Midea…
##  8 37    North Carolina P001001   9535483 (((1192302 1527379, 1192529 15… South…
##  9 39    Ohio           P001001  11536504 (((1085606 2155413, 1085897 21… Great…
## 10 42    Pennsylvania   P001001  12702379 (((1733137 2053210, 1731881 20… Midea…
## # … with 39 more rows
continental_usa_dissolve<-continental_USA_regions_projected %>% 
                              group_by(region) %>% 
                              summarise()
tm_shape(continental_usa_dissolve)+
  tm_polygons()

https://guides.library.duke.edu/r-geospatial/CRS https://mgimond.github.io/Spatial/vector-operations-in-r.html

4 Clipping polygons

arbitrary_bounding_box<-
  st_bbox(c(xmin=500000, xmax=1000000, ymin=1100000, ymax=2000000)) %>% 
    st_as_sfc() %>% 
    st_set_crs(5070)
tm_shape(continental_USA_regions_projected)+
  tm_polygons()+
tm_shape(arbitrary_bounding_box)+
  tm_polygons(alpha=0, lwd=5)

states_bounding_box_intersection<-st_intersection(continental_USA_regions_projected, arbitrary_bounding_box)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
tm_shape(states_bounding_box_intersection)+
  tm_polygons()

states_bounding_box_intersect<-
  continental_USA_regions_projected %>% 
          st_filter(arbitrary_bounding_box, .predicate=st_intersects)
tm_shape(states_bounding_box_intersect)+
  tm_polygons()

4.1 Union

arbitrary_bounding_box<-
  st_bbox(c(xmin=500000, xmax=1000000, ymin=1100000, ymax=2000000)) %>% 
    st_as_sfc() %>% 
    st_set_crs(5070)
arbitrary_bounding_box_two<-
    st_bbox(c(xmin=75000, xmax=930000, ymin=1300000, ymax=2100000)) %>% 
    st_as_sfc() %>% 
    st_set_crs(5070)
tm_shape(continental_USA_regions_projected)+
  tm_polygons()+
tm_shape(arbitrary_bounding_box)+
  tm_borders(lwd=5)+
tm_shape(arbitrary_bounding_box_two)+
  tm_borders("red", lwd=5)

bounding_box_union<-st_union(arbitrary_bounding_box, arbitrary_bounding_box_two)
tm_shape(continental_USA_regions_projected)+
  tm_polygons()+
tm_shape(bounding_box_union)+
  tm_borders(lwd=5)

bounding_box_intersection<-st_intersection(arbitrary_bounding_box, arbitrary_bounding_box_two)
tm_shape(continental_USA_regions_projected)+
  tm_polygons()+
tm_shape(bounding_box_intersection)+
  tm_borders(lwd=5)

4.2 Inverse clip/Erase

states_bounding_box_inverse<-st_difference(continental_USA_regions_projected, arbitrary_bounding_box)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
tm_shape(states_bounding_box_inverse)+
  tm_polygons()

https://cran.r-project.org/web/packages/sf/vignettes/sf4.html https://www.r-bloggers.com/2014/07/clipping-spatial-data-in-r/ https://mgimond.github.io/Spatial/vector-operations-in-r.html#clipping-spatial-objects-using-other-spatial-objects

5 Geocoding

CO_epa<-read_csv("https://www.dropbox.com/s/43pcrmvhs0dqcwv/STATE_SINGLE_CO.CSV?dl=1")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_character(),
##   REGISTRY_ID = col_double(),
##   TRIBAL_LAND_NAME = col_logical(),
##   CONGRESSIONAL_DIST_NUM = col_double(),
##   CENSUS_BLOCK_CODE = col_double(),
##   HUC_CODE = col_double(),
##   EPA_REGION_CODE = col_double(),
##   US_MEXICO_BORDER_IND = col_logical(),
##   SOURCE_DESC = col_logical()
## )
## ℹ Use `spec()` for the full column specifications.
## Warning: 9 parsing failures.
##   row              col           expected                                                              actual                                                                 file
## 11561 TRIBAL_LAND_NAME 1/0/T/F/TRUE/FALSE SOUTHERN UTE INDIAN TRIBE OF THE SOUTHERN UTE RESERVATION, COLORADO 'https://www.dropbox.com/s/43pcrmvhs0dqcwv/STATE_SINGLE_CO.CSV?dl=1'
## 11562 TRIBAL_LAND_NAME 1/0/T/F/TRUE/FALSE SOUTHERN UTE INDIAN TRIBE OF THE SOUTHERN UTE RESERVATION, COLORADO 'https://www.dropbox.com/s/43pcrmvhs0dqcwv/STATE_SINGLE_CO.CSV?dl=1'
## 46854 TRIBAL_LAND_NAME 1/0/T/F/TRUE/FALSE SOUTHERN UTE INDIAN TRIBE OF THE SOUTHERN UTE RESERVATION, COLORADO 'https://www.dropbox.com/s/43pcrmvhs0dqcwv/STATE_SINGLE_CO.CSV?dl=1'
## 46857 TRIBAL_LAND_NAME 1/0/T/F/TRUE/FALSE SOUTHERN UTE INDIAN TRIBE OF THE SOUTHERN UTE RESERVATION, COLORADO 'https://www.dropbox.com/s/43pcrmvhs0dqcwv/STATE_SINGLE_CO.CSV?dl=1'
## 46858 TRIBAL_LAND_NAME 1/0/T/F/TRUE/FALSE SOUTHERN UTE INDIAN TRIBE OF THE SOUTHERN UTE RESERVATION, COLORADO 'https://www.dropbox.com/s/43pcrmvhs0dqcwv/STATE_SINGLE_CO.CSV?dl=1'
## ..... ................ .................. ................................................................... ....................................................................
## See problems(...) for more details.
CO_epa_boulder<-CO_epa %>% filter(COUNTY_NAME=="BOULDER")
CO_epa_boulder_geocoded_census<-CO_epa_boulder %>% 
                            geocode(street=LOCATION_ADDRESS, city=CITY_NAME, postalcode = POSTAL_CODE, state=STATE_NAME, limit=1, method="census", full_results=TRUE)
CO_epa_boulder_points<-CO_epa_boulder_geocoded_census %>% 
                        drop_na(long) %>% 
                        st_as_sf(coords=c("long", "lat"), crs=4326)
CO_counties<-get_decennial(geography = "county",
                           state="CO",
                           variables = "P001001",
                           year = 2010,
                           geometry=TRUE) %>% 
                      st_transform(4326)
tm_shape(CO_counties)+
  tm_polygons()+
tm_shape(CO_epa_boulder_points)+
  tm_dots()

boulder_county<-CO_counties %>% 
                  filter(GEOID=="08013")
tm_shape(boulder_county)+
  tm_polygons()+
tm_shape(CO_epa_boulder_points)+
  tm_dots("orange")

boulder_county_projected<-st_transform(boulder_county, 2231)
CO_epa_boulder_points_projected<-st_transform(CO_epa_boulder_points, 2231)
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(CO_epa_boulder_points_projected)+
  tm_dots("orange")

CO_epa_boulder_points_cleaned<-
  CO_epa_boulder_points_projected %>% 
    st_filter(boulder_county_projected, .predicate=st_intersects)
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(CO_epa_boulder_points_cleaned)+
  tm_dots("orange")

6 Distance and Area

6.1 Load data

setwd("class_notes/class2/data")
download.file(url="https://geo.colorado.edu/apps/geolibrary/datasets/caiHospitals.zip", destfile="hospitals.zip")

unzip(zipfile = "hospitals.zip")

hospital_points<-st_read(dsn="CAI_Hospitals.shp")
## Reading layer `CAI_Hospitals' from data source `/Users/adra7980/Documents/git_repositories/ARSC5040_GIS/class_notes/class2/data/CAI_Hospitals.shp' using driver `ESRI Shapefile'
## Simple feature collection with 182 features and 4 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -108.8045 ymin: 37.17322 xmax: -102.2349 ymax: 40.99407
## geographic CRS: WGS 84
hospital_points
## Simple feature collection with 182 features and 4 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -108.8045 ymin: 37.17322 xmax: -102.2349 ymax: 40.99407
## geographic CRS: WGS 84
## First 10 features:
##    OBJECTID                                       NAME STCTYFIPS ELEV_METER
## 1         1             The Memorial Hospital at Craig     08081       1929
## 2         2                       Valley View Hospital     08045       1790
## 3         3    Saint Marys Hospital and Medical Center     08077       1421
## 4         4                  Sierra Vista Nursing Home     08069       1526
## 5         5             Memorial Hospital (historical)     08069       1523
## 6         6 Boulder Community Hospital Mapleton Center     08013       1685
## 7         7              North Colorado Medical Center     08123       1443
## 8         8            Exempla Lutheran Medical Center     08059       1673
## 9         9        Sands House Sanatarium (historical)     08059       1638
## 10       10          Offielo Nursing Home (historical)     08031       1640
##                      geometry
## 1  POINT (-107.5798 40.51853)
## 2  POINT (-107.3216 39.53252)
## 3  POINT (-108.5627 39.09045)
## 4  POINT (-105.0928 40.40026)
## 5  POINT (-105.0903 40.39721)
## 6  POINT (-105.2933 40.02131)
## 7  POINT (-104.7089 40.41478)
## 8  POINT (-105.0905 39.76845)
## 9  POINT (-105.0555 39.75554)
## 10 POINT (-105.0297 39.76388)
tm_shape(CO_counties)+
  tm_polygons()+
tm_shape(hospital_points)+
  tm_dots()

boulder_hospitals<-hospital_points %>% 
                    filter(STCTYFIPS=="08013") %>% 
                    st_transform(2231)
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(boulder_hospitals)+
  tm_dots()

6.2 Extracting distances based on a single dataset

boulder_hospital_distancematrix<-st_distance(boulder_hospitals)
boulder_hospital_distancematrix
## Units: [US_survey_foot]
##            [,1]      [,2]       [,3]     [,4]      [,5]     [,6]       [,7]
##  [1,]     0.000  6852.585  3377.4033 74980.36 54937.265 16096.58 47021.9045
##  [2,]  6852.585     0.000  4106.7019 68172.18 53107.427 14493.88 47536.8826
##  [3,]  3377.403  4106.702     0.0000 71817.39 52592.319 13591.57 45634.9733
##  [4,] 74980.361 68172.179 71817.3928     0.00 71655.423 67834.68 84189.3672
##  [5,] 54937.265 53107.427 52592.3194 71655.42     0.000 39001.88 18643.4002
##  [6,] 16096.580 14493.875 13591.5733 67834.68 39001.877     0.00 33300.9788
##  [7,] 47021.904 47536.883 45634.9733 84189.37 18643.400 33300.98     0.0000
##  [8,] 47790.557 48228.137 46370.0417 84116.56 17980.654 33952.32   909.1505
##  [9,]  3752.267  4004.625   409.6008 71534.11 52213.332 13211.52 45334.0385
## [10,] 60843.821 59479.936 58685.6151 77920.28  7328.755 45156.99 19526.8907
## [11,] 47917.763 48340.369 46490.7165 84090.30 17856.784 34057.39  1068.2121
## [12,]  3323.383  4402.229   338.5010 72002.43 52397.404 13401.90 45355.9289
##             [,8]       [,9]     [,10]      [,11]      [,12]
##  [1,] 47790.5570  3752.2675 60843.821 47917.7628  3323.3833
##  [2,] 48228.1370  4004.6252 59479.936 48340.3693  4402.2294
##  [3,] 46370.0417   409.6008 58685.615 46490.7165   338.5010
##  [4,] 84116.5575 71534.1090 77920.275 84090.2961 72002.4315
##  [5,] 17980.6543 52213.3323  7328.755 17856.7840 52397.4037
##  [6,] 33952.3219 13211.5189 45156.994 34057.3877 13401.9015
##  [7,]   909.1505 45334.0385 19526.891  1068.2121 45355.9289
##  [8,]     0.0000 46065.8718 18676.601   159.6288 46093.2449
##  [9,] 46065.8718     0.0000 58319.042 46185.9258   468.5123
## [10,] 18676.6014 58319.0419     0.000 18523.1937 58470.8459
## [11,]   159.6288 46185.9258 18523.194     0.0000 46214.3592
## [12,] 46093.2449   468.5123 58470.846 46214.3592     0.0000
rownames(boulder_hospital_distancematrix)<-boulder_hospitals$NAME
colnames(boulder_hospital_distancematrix)<-boulder_hospitals$NAME

boulder_hospital_distancematrix
## Units: [US_survey_foot]
##                                            Boulder Community Hospital Mapleton Center
## Boulder Community Hospital Mapleton Center                                      0.000
## Boulder County Hospital (historical)                                         6852.585
## Boulder Community Hospital                                                   3377.403
## Longmont United Hospital                                                    74980.361
## Community Medical Center Lafayette                                          54937.265
## Boulder Community Foothills Hospital                                        16096.580
## Avista Adventist Hospital                                                   47021.904
## Boulder Medical Center Hospital                                             47790.557
## Boulder Medical Center                                                       3752.267
## Exempla Good Samaritan Medical Center                                       60843.821
## Centennial Peaks Hospital                                                   47917.763
## Boulder Community Hospital Surgery Center                                    3323.383
##                                            Boulder County Hospital (historical)
## Boulder Community Hospital Mapleton Center                             6852.585
## Boulder County Hospital (historical)                                      0.000
## Boulder Community Hospital                                             4106.702
## Longmont United Hospital                                              68172.179
## Community Medical Center Lafayette                                    53107.427
## Boulder Community Foothills Hospital                                  14493.875
## Avista Adventist Hospital                                             47536.883
## Boulder Medical Center Hospital                                       48228.137
## Boulder Medical Center                                                 4004.625
## Exempla Good Samaritan Medical Center                                 59479.936
## Centennial Peaks Hospital                                             48340.369
## Boulder Community Hospital Surgery Center                              4402.229
##                                            Boulder Community Hospital
## Boulder Community Hospital Mapleton Center                  3377.4033
## Boulder County Hospital (historical)                        4106.7019
## Boulder Community Hospital                                     0.0000
## Longmont United Hospital                                   71817.3928
## Community Medical Center Lafayette                         52592.3194
## Boulder Community Foothills Hospital                       13591.5733
## Avista Adventist Hospital                                  45634.9733
## Boulder Medical Center Hospital                            46370.0417
## Boulder Medical Center                                       409.6008
## Exempla Good Samaritan Medical Center                      58685.6151
## Centennial Peaks Hospital                                  46490.7165
## Boulder Community Hospital Surgery Center                    338.5010
##                                            Longmont United Hospital
## Boulder Community Hospital Mapleton Center                 74980.36
## Boulder County Hospital (historical)                       68172.18
## Boulder Community Hospital                                 71817.39
## Longmont United Hospital                                       0.00
## Community Medical Center Lafayette                         71655.42
## Boulder Community Foothills Hospital                       67834.68
## Avista Adventist Hospital                                  84189.37
## Boulder Medical Center Hospital                            84116.56
## Boulder Medical Center                                     71534.11
## Exempla Good Samaritan Medical Center                      77920.28
## Centennial Peaks Hospital                                  84090.30
## Boulder Community Hospital Surgery Center                  72002.43
##                                            Community Medical Center Lafayette
## Boulder Community Hospital Mapleton Center                          54937.265
## Boulder County Hospital (historical)                                53107.427
## Boulder Community Hospital                                          52592.319
## Longmont United Hospital                                            71655.423
## Community Medical Center Lafayette                                      0.000
## Boulder Community Foothills Hospital                                39001.877
## Avista Adventist Hospital                                           18643.400
## Boulder Medical Center Hospital                                     17980.654
## Boulder Medical Center                                              52213.332
## Exempla Good Samaritan Medical Center                                7328.755
## Centennial Peaks Hospital                                           17856.784
## Boulder Community Hospital Surgery Center                           52397.404
##                                            Boulder Community Foothills Hospital
## Boulder Community Hospital Mapleton Center                             16096.58
## Boulder County Hospital (historical)                                   14493.88
## Boulder Community Hospital                                             13591.57
## Longmont United Hospital                                               67834.68
## Community Medical Center Lafayette                                     39001.88
## Boulder Community Foothills Hospital                                       0.00
## Avista Adventist Hospital                                              33300.98
## Boulder Medical Center Hospital                                        33952.32
## Boulder Medical Center                                                 13211.52
## Exempla Good Samaritan Medical Center                                  45156.99
## Centennial Peaks Hospital                                              34057.39
## Boulder Community Hospital Surgery Center                              13401.90
##                                            Avista Adventist Hospital
## Boulder Community Hospital Mapleton Center                47021.9045
## Boulder County Hospital (historical)                      47536.8826
## Boulder Community Hospital                                45634.9733
## Longmont United Hospital                                  84189.3672
## Community Medical Center Lafayette                        18643.4002
## Boulder Community Foothills Hospital                      33300.9788
## Avista Adventist Hospital                                     0.0000
## Boulder Medical Center Hospital                             909.1505
## Boulder Medical Center                                    45334.0385
## Exempla Good Samaritan Medical Center                     19526.8907
## Centennial Peaks Hospital                                  1068.2121
## Boulder Community Hospital Surgery Center                 45355.9289
##                                            Boulder Medical Center Hospital
## Boulder Community Hospital Mapleton Center                      47790.5570
## Boulder County Hospital (historical)                            48228.1370
## Boulder Community Hospital                                      46370.0417
## Longmont United Hospital                                        84116.5575
## Community Medical Center Lafayette                              17980.6543
## Boulder Community Foothills Hospital                            33952.3219
## Avista Adventist Hospital                                         909.1505
## Boulder Medical Center Hospital                                     0.0000
## Boulder Medical Center                                          46065.8718
## Exempla Good Samaritan Medical Center                           18676.6014
## Centennial Peaks Hospital                                         159.6288
## Boulder Community Hospital Surgery Center                       46093.2449
##                                            Boulder Medical Center
## Boulder Community Hospital Mapleton Center              3752.2675
## Boulder County Hospital (historical)                    4004.6252
## Boulder Community Hospital                               409.6008
## Longmont United Hospital                               71534.1090
## Community Medical Center Lafayette                     52213.3323
## Boulder Community Foothills Hospital                   13211.5189
## Avista Adventist Hospital                              45334.0385
## Boulder Medical Center Hospital                        46065.8718
## Boulder Medical Center                                     0.0000
## Exempla Good Samaritan Medical Center                  58319.0419
## Centennial Peaks Hospital                              46185.9258
## Boulder Community Hospital Surgery Center                468.5123
##                                            Exempla Good Samaritan Medical Center
## Boulder Community Hospital Mapleton Center                             60843.821
## Boulder County Hospital (historical)                                   59479.936
## Boulder Community Hospital                                             58685.615
## Longmont United Hospital                                               77920.275
## Community Medical Center Lafayette                                      7328.755
## Boulder Community Foothills Hospital                                   45156.994
## Avista Adventist Hospital                                              19526.891
## Boulder Medical Center Hospital                                        18676.601
## Boulder Medical Center                                                 58319.042
## Exempla Good Samaritan Medical Center                                      0.000
## Centennial Peaks Hospital                                              18523.194
## Boulder Community Hospital Surgery Center                              58470.846
##                                            Centennial Peaks Hospital
## Boulder Community Hospital Mapleton Center                47917.7628
## Boulder County Hospital (historical)                      48340.3693
## Boulder Community Hospital                                46490.7165
## Longmont United Hospital                                  84090.2961
## Community Medical Center Lafayette                        17856.7840
## Boulder Community Foothills Hospital                      34057.3877
## Avista Adventist Hospital                                  1068.2121
## Boulder Medical Center Hospital                             159.6288
## Boulder Medical Center                                    46185.9258
## Exempla Good Samaritan Medical Center                     18523.1937
## Centennial Peaks Hospital                                     0.0000
## Boulder Community Hospital Surgery Center                 46214.3592
##                                            Boulder Community Hospital Surgery Center
## Boulder Community Hospital Mapleton Center                                 3323.3833
## Boulder County Hospital (historical)                                       4402.2294
## Boulder Community Hospital                                                  338.5010
## Longmont United Hospital                                                  72002.4315
## Community Medical Center Lafayette                                        52397.4037
## Boulder Community Foothills Hospital                                      13401.9015
## Avista Adventist Hospital                                                 45355.9289
## Boulder Medical Center Hospital                                           46093.2449
## Boulder Medical Center                                                      468.5123
## Exempla Good Samaritan Medical Center                                     58470.8459
## Centennial Peaks Hospital                                                 46214.3592
## Boulder Community Hospital Surgery Center                                     0.0000
boulder_hospital_distancematrix["Longmont United Hospital", "Boulder Community Hospital"]
## 71817.39 [US_survey_foot]

6.3 Extracting distances between features in different datasets

fire stations

boulder_fire_stations<-st_read("Fire_Stations.shp")
## Reading layer `Fire_Stations' from data source `/Users/adra7980/Documents/git_repositories/ARSC5040_GIS/class_notes/class2/data/fire_stations/Fire_Stations.shp' using driver `ESRI Shapefile'
## Simple feature collection with 90 features and 19 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -105.5698 ymin: 39.80299 xmax: -104.9453 ymax: 40.30518
## geographic CRS: WGS 84
boulder_fire_stations
## Simple feature collection with 90 features and 19 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: -105.5698 ymin: 39.80299 xmax: -104.9453 ymax: 40.30518
## geographic CRS: WGS 84
## First 10 features:
##    OBJECTID                                   District          Chief
## 1         1         Sugarloaf Fire Protection District Andrew Goldman
## 2         2         Nederland Fire Protection District  Michael Scott
## 3         3         Nederland Fire Protection District  Michael Scott
## 4         4         Nederland Fire Protection District  Michael Scott
## 5         5        Allenspark Fire Protection District   Leo Touzjian
## 6         6     Boulder Rural Fire Protection District    Greg Schwab
## 7         7  Boulder Mountain Fire Protection District    John Benson
## 8         8  Boulder Mountain Fire Protection District    John Benson
## 9         9 Coal Creek Canyon Fire Protection District    Garret Ball
## 10       10 Coal Creek Canyon Fire Protection District    Garret Ball
##                             Website1            Address       City State   Zip
## 1              http://www.slfpd.org/ 1677 Lost Angel Rd    Boulder    CO 80302
## 2               http://www.nfpd.org/   555 Eldorado Ave  Nederland    CO 80466
## 3               http://www.nfpd.org/      2815 Ridge Rd  Nederland    CO 80466
## 4               http://www.nfpd.org/       650 W 4th St  Nederland    CO 80466
## 5     http://www.allensparkfire.com/        14861 Hwy 7 Allenspark    CO 80510
## 6                   http://brfd.org/    6230 Lookout Rd    Boulder    CO 80301
## 7             https://www.bmfpd.org/     1905 Linden Dr    Boulder    CO 80304
## 8             https://www.bmfpd.org/     50 Overlook Ln    Boulder    CO 80302
## 9  http://www.coalcreekcanyonfd.org/   30579 Highway 72     Golden    CO 80403
## 10 http://www.coalcreekcanyonfd.org/     34697 Gap Road     Golden    CO 80403
##    Captain                         Email Status          Phone Paid_Emplo
## 1     <NA>                 pio@slfpd.org <null> (303) 442-1354       <NA>
## 2     <NA>                admin@nfpd.org <null> (303) 258-9555       <NA>
## 3     <NA>                admin@nfpd.org <null> (303) 258-0310       <NA>
## 4     <NA>                admin@nfpd.org <null> (303) 258-9161       <NA>
## 5     <NA>       info@allensparkfire.com <null> (303) 747-2586       <NA>
## 6     <NA>          greg.schwab@brfr.org <null> (303) 530-9575       <NA>
## 7     <NA> chief@bouldermountainfire.org <null> (303) 440-0235       <NA>
## 8     <NA> chief@bouldermountainfire.org <null> (303) 440-0235       <NA>
## 9     <NA> general@coalcreekcanyonfd.org <null> (303) 642-3121       <NA>
## 10    <NA> general@coalcreekcanyonfd.org <null> (303) 642-3466       <NA>
##    Volunteers                      Station_Na            BRETSA_Nam BRETSA_Cod
## 1        <NA>            Sugar Loaf Station 1       SUGAR LOAF FIRE       <NA>
## 2        <NA>             Nederland Station 3        NEDERLAND FIRE       <NA>
## 3        <NA>             Nederland Station 2        NEDERLAND FIRE       <NA>
## 4        <NA>             Nederland Station 1        NEDERLAND FIRE       <NA>
## 5        <NA>            Allenspark Station 1       ALLENSPARK FIRE       <NA>
## 6        <NA>         Boulder Rural Station 1    BOULDER RURAL FIRE       <NA>
## 7        <NA>                 BMFPD Station 1 BOULDER MOUNTAIN FIRE       <NA>
## 8        <NA>                 BMFPD Station 2 BOULDER MOUNTAIN FIRE       <NA>
## 9        <NA> Coal Creek Canyon FPD Station 1       COAL CREEK FIRE       <NA>
## 10       <NA> Coal Creek Canyon FPD Station 4       COAL CREEK FIRE       <NA>
##    Equipment  Notes                   geometry
## 1     <null> <null> POINT (-105.4043 40.01912)
## 2     <null> <null>  POINT (-105.5698 39.9494)
## 3     <null> <null> POINT (-105.4638 39.98126)
## 4     <null> <null> POINT (-105.5165 39.96397)
## 5     <null> <null>  POINT (-105.5285 40.1968)
## 6     <null> <null>  POINT (-105.208 40.07039)
## 7     <null> <null>  POINT (-105.3106 40.0503)
## 8     <null> <null>  POINT (-105.3553 40.0778)
## 9     <null> <null> POINT (-105.3474 39.90607)
## 10    <null> <null> POINT (-105.3897 39.87755)
boulder_fire_stations_projected<-boulder_fire_stations %>%  
                                    st_transform(2231)
boulder_hospital_firstation_distancematrix<-
  st_distance(boulder_hospitals, boulder_fire_stations_projected)
firestations_hospitals<-
  tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(boulder_fire_stations_projected)+
  tm_dots("red", size=0.1)+
tm_shape(boulder_hospitals)+
  tm_dots("blue", size=0.1)

firestations_hospitals

rownames(boulder_hospital_firstation_distancematrix)<-boulder_hospitals$NAME
colnames(boulder_hospital_firstation_distancematrix)<-boulder_fire_stations_projected$Station_Na

boulder_hospital_firstation_distancematrix
## Units: [US_survey_foot]
##                                            Sugar Loaf Station 1
## Boulder Community Hospital Mapleton Center             31083.71
## Boulder County Hospital (historical)                   35353.00
## Boulder Community Hospital                             34051.63
## Longmont United Hospital                               97891.50
## Community Medical Center Lafayette                     85360.90
## Boulder Community Foothills Hospital                   47078.03
## Avista Adventist Hospital                              74856.08
## Boulder Medical Center Hospital                        75715.35
## Boulder Medical Center                                 34460.99
## Exempla Good Samaritan Medical Center                  90789.24
## Centennial Peaks Hospital                              75860.99
## Boulder Community Hospital Surgery Center              34141.32
##                                            Nederland Station 3
## Boulder Community Hospital Mapleton Center            81775.10
## Boulder County Hospital (historical)                  87200.52
## Boulder Community Hospital                            85071.81
## Longmont United Hospital                             150361.43
## Community Medical Center Lafayette                   131642.63
## Boulder Community Foothills Hospital                  96591.98
## Avista Adventist Hospital                            117182.77
## Boulder Medical Center Hospital                      118091.91
## Boulder Medical Center                                85471.23
## Exempla Good Samaritan Medical Center                135701.22
## Centennial Peaks Hospital                            118250.94
## Boulder Community Hospital Surgery Center             85074.08
##                                            Nederland Station 2
## Boulder Community Hospital Mapleton Center            49935.00
## Boulder County Hospital (historical)                  55307.09
## Boulder Community Hospital                            53212.04
## Longmont United Hospital                             119517.14
## Community Medical Center Lafayette                   101240.10
## Boulder Community Foothills Hospital                  65018.16
## Avista Adventist Hospital                             88094.82
## Boulder Medical Center Hospital                       88997.11
## Boulder Medical Center                                53613.37
## Exempla Good Samaritan Medical Center                105821.89
## Centennial Peaks Hospital                             89153.11
## Boulder Community Hospital Surgery Center             53222.13
##                                            Nederland Station 1
## Boulder Community Hospital Mapleton Center            65913.01
## Boulder County Hospital (historical)                  71349.08
## Boulder Community Hospital                            69208.11
## Longmont United Hospital                             135094.12
## Community Medical Center Lafayette                   116278.89
## Boulder Community Foothills Hospital                  80795.69
## Avista Adventist Hospital                            102310.49
## Boulder Medical Center Hospital                      103218.72
## Boulder Medical Center                                69607.64
## Exempla Good Samaritan Medical Center                120544.60
## Centennial Peaks Hospital                            103376.87
## Boulder Community Hospital Surgery Center             69210.91
##                                            Allenspark Station 1
## Boulder Community Hospital Mapleton Center             91717.54
## Boulder County Hospital (historical)                   90547.07
## Boulder Community Hospital                             92611.85
## Longmont United Hospital                              112521.32
## Community Medical Center Lafayette                    141690.07
## Boulder Community Foothills Hospital                  104909.94
## Avista Adventist Hospital                             138081.37
## Boulder Medical Center Hospital                       138775.20
## Boulder Medical Center                                 92883.74
## Exempla Good Samaritan Medical Center                 148635.51
## Centennial Peaks Hospital                             138887.38
## Boulder Community Hospital Surgery Center              92909.77
##                                            Boulder Rural Station 1
## Boulder Community Hospital Mapleton Center                29845.23
## Boulder County Hospital (historical)                      23568.38
## Boulder Community Hospital                                26484.92
## Longmont United Hospital                                  46716.50
## Community Medical Center Lafayette                        42530.64
## Boulder Community Foothills Hospital                      21240.54
## Avista Adventist Hospital                                 45929.29
## Boulder Medical Center Hospital                           46248.03
## Boulder Medical Center                                    26135.63
## Exempla Good Samaritan Medical Center                     49826.37
## Centennial Peaks Hospital                                 46291.78
## Boulder Community Hospital Surgery Center                 26592.34
##                                            BMFPD Station 1 BMFPD Station 2
## Boulder Community Hospital Mapleton Center       11607.429        26917.54
## Boulder County Hospital (historical)              9728.971        25692.91
## Boulder Community Hospital                       11693.935        27631.81
## Longmont United Hospital                         70483.604        74511.99
## Community Medical Center Lafayette               62735.168        78223.98
## Boulder Community Foothills Hospital             24217.908        40170.08
## Avista Adventist Hospital                        57106.308        73150.18
## Boulder Medical Center Hospital                  57816.356        73859.95
## Boulder Medical Center                           11933.095        27901.10
## Exempla Good Samaritan Medical Center            69173.075        84836.14
## Centennial Peaks Hospital                        57932.053        73975.46
## Boulder Community Hospital Surgery Center        12008.857        27931.99
##                                            Coal Creek Canyon FPD Station 1
## Boulder Community Hospital Mapleton Center                        44629.03
## Boulder County Hospital (historical)                              51341.61
## Boulder Community Hospital                                        47310.39
## Longmont United Hospital                                         118126.89
## Community Medical Center Lafayette                                74602.48
## Boulder Community Foothills Hospital                              50815.82
## Avista Adventist Hospital                                         57328.11
## Boulder Medical Center Hospital                                   58198.75
## Boulder Medical Center                                            47508.35
## Exempla Good Samaritan Medical Center                             76829.54
## Centennial Peaks Hospital                                         58355.26
## Boulder Community Hospital Surgery Center                         47058.53
##                                            Coal Creek Canyon FPD Station 4
## Boulder Community Hospital Mapleton Center                        58921.03
## Boulder County Hospital (historical)                              65750.26
## Boulder Community Hospital                                        61832.07
## Longmont United Hospital                                         133269.20
## Community Medical Center Lafayette                                89732.50
## Boulder Community Foothills Hospital                              66363.61
## Avista Adventist Hospital                                         72006.76
## Boulder Medical Center Hospital                                   72850.44
## Boulder Medical Center                                            62069.11
## Exempla Good Samaritan Medical Center                             91526.42
## Centennial Peaks Hospital                                         73003.51
## Boulder Community Hospital Surgery Center                         61607.43
##                                            Four Mile Logan Mill Station
## Boulder Community Hospital Mapleton Center                     21401.81
## Boulder County Hospital (historical)                           23767.72
## Boulder Community Hospital                                     23634.70
## Longmont United Hospital                                       84096.53
## Community Medical Center Lafayette                             76218.30
## Boulder Community Foothills Hospital                           37224.26
## Avista Adventist Hospital                                      68104.77
## Boulder Medical Center Hospital                                68902.51
## Boulder Medical Center                                         24019.19
## Exempla Good Samaritan Medical Center                          82225.68
## Centennial Peaks Hospital                                      69035.34
## Boulder Community Hospital Surgery Center                      23822.88
##                                            Four Mile Salina Station
## Boulder Community Hospital Mapleton Center                 26442.85
## Boulder County Hospital (historical)                       27944.82
## Boulder Community Hospital                                 28367.73
## Longmont United Hospital                                   84420.45
## Community Medical Center Lafayette                         80888.09
## Boulder Community Foothills Hospital                       41913.84
## Avista Adventist Hospital                                  73382.38
## Boulder Medical Center Hospital                            74166.86
## Boulder Medical Center                                     28732.41
## Exempla Good Samaritan Medical Center                      87051.17
## Centennial Peaks Hospital                                  74297.00
## Boulder Community Hospital Surgery Center                  28588.15
##                                            Four Mile Wall Street Station
## Boulder Community Hospital Mapleton Center                      26286.47
## Boulder County Hospital (historical)                            28951.00
## Boulder Community Hospital                                      28674.27
## Longmont United Hospital                                        88394.26
## Community Medical Center Lafayette                              81202.36
## Boulder Community Foothills Hospital                            42241.88
## Avista Adventist Hospital                                       72626.89
## Boulder Medical Center Hospital                                 73439.95
## Boulder Medical Center                                          29065.30
## Exempla Good Samaritan Medical Center                           87124.07
## Centennial Peaks Hospital                                       73575.87
## Boulder Community Hospital Surgery Center                       28847.75
##                                            Gold Hill Fire Protection District
## Boulder Community Hospital Mapleton Center                           36796.93
## Boulder County Hospital (historical)                                 38378.84
## Boulder Community Hospital                                           38809.61
## Longmont United Hospital                                             91382.30
## Community Medical Center Lafayette                                   91346.02
## Boulder Community Foothills Hospital                                 52367.45
## Avista Adventist Hospital                                            83599.28
## Boulder Medical Center Hospital                                      84396.32
## Boulder Medical Center                                               39177.35
## Exempla Good Samaritan Medical Center                                97495.15
## Centennial Peaks Hospital                                            84528.95
## Boulder Community Hospital Surgery Center                            39025.17
##                                            Indian Peaks Station 1
## Boulder Community Hospital Mapleton Center               62658.25
## Boulder County Hospital (historical)                     64776.64
## Boulder Community Hospital                               64938.72
## Longmont United Hospital                                113829.36
## Community Medical Center Lafayette                      117527.32
## Boulder Community Foothills Hospital                     78530.16
## Avista Adventist Hospital                               108735.65
## Boulder Medical Center Hospital                         109567.59
## Boulder Medical Center                                   65320.54
## Exempla Good Samaritan Medical Center                   123501.36
## Centennial Peaks Hospital                               109707.33
## Boulder Community Hospital Surgery Center                65130.52
##                                            Lafayette Fire Department Station 1
## Boulder Community Hospital Mapleton Center                           56468.559
## Boulder County Hospital (historical)                                 53934.971
## Boulder Community Hospital                                           53875.734
## Longmont United Hospital                                             66523.894
## Community Medical Center Lafayette                                    6032.733
## Boulder Community Foothills Hospital                                 40374.305
## Avista Adventist Hospital                                            24322.741
## Boulder Medical Center Hospital                                      23720.532
## Boulder Medical Center                                               53481.842
## Exempla Good Samaritan Medical Center                                11401.960
## Centennial Peaks Hospital                                            23606.155
## Boulder Community Hospital Surgery Center                            53712.650
##                                            Jamestown Fire Hall
## Boulder Community Hospital Mapleton Center            42965.11
## Boulder County Hospital (historical)                  41062.00
## Boulder Community Hospital                            43432.10
## Longmont United Hospital                              76626.05
## Community Medical Center Lafayette                    92223.49
## Boulder Community Foothills Hospital                  55314.37
## Avista Adventist Hospital                             88565.88
## Boulder Medical Center Hospital                       89240.25
## Boulder Medical Center                                43670.02
## Exempla Good Samaritan Medical Center                 99089.36
## Centennial Peaks Hospital                             89348.87
## Boulder Community Hospital Surgery Center             43745.72
##                                            Louisville Station 1
## Boulder Community Hospital Mapleton Center            47357.926
## Boulder County Hospital (historical)                  46069.288
## Boulder Community Hospital                            45203.227
## Longmont United Hospital                              72806.982
## Community Medical Center Lafayette                     8381.618
## Boulder Community Foothills Hospital                  31694.226
## Avista Adventist Hospital                             12402.343
## Boulder Medical Center Hospital                       12023.306
## Boulder Medical Center                                44838.193
## Exempla Good Samaritan Medical Center                 13488.449
## Centennial Peaks Hospital                             11949.385
## Boulder Community Hospital Surgery Center             44986.580
##                                            Louisville Station 2 Lyons Station 1
## Boulder Community Hospital Mapleton Center            40979.133        74020.38
## Boulder County Hospital (historical)                  40615.204        67955.37
## Boulder Community Hospital                            39183.764        72027.21
## Longmont United Hospital                              76209.085        41955.15
## Community Medical Center Lafayette                    16713.301        97780.52
## Boulder Community Foothills Hospital                  26140.667        75938.88
## Avista Adventist Hospital                              8602.903       103974.29
## Boulder Medical Center Hospital                        8895.193       104257.40
## Boulder Medical Center                                38848.231        71957.49
## Exempla Good Samaritan Medical Center                 20733.182       105002.94
## Centennial Peaks Hospital                              8941.341       104293.81
## Boulder Community Hospital Surgery Center             38933.162        72338.78
##                                            Lyons Station 2
## Boulder Community Hospital Mapleton Center        94583.88
## Boulder County Hospital (historical)              88791.48
## Boulder Community Hospital                        92810.97
## Longmont United Hospital                          57437.75
## Community Medical Center Lafayette               119003.44
## Boulder Community Foothills Hospital              97420.02
## Avista Adventist Hospital                        125625.00
## Boulder Medical Center Hospital                  125899.85
## Boulder Medical Center                            92771.54
## Exempla Good Samaritan Medical Center            126169.30
## Centennial Peaks Hospital                        125934.65
## Boulder Community Hospital Surgery Center         93131.57
##                                            Mountain View Fire Rescue Station 13
## Boulder Community Hospital Mapleton Center                             79194.81
## Boulder County Hospital (historical)                                   73021.14
## Boulder Community Hospital                                             75818.90
## Longmont United Hospital                                               24999.68
## Community Medical Center Lafayette                                     57366.00
## Boulder Community Foothills Hospital                                   67572.73
## Avista Adventist Hospital                                              73471.93
## Boulder Medical Center Hospital                                        73144.91
## Boulder Medical Center                                                 75453.76
## Exempla Good Samaritan Medical Center                                  62224.74
## Centennial Peaks Hospital                                              73075.10
## Boulder Community Hospital Surgery Center                              75900.20
##                                            Mountain View Fire Rescue Station 3
## Boulder Community Hospital Mapleton Center                           114300.91
## Boulder County Hospital (historical)                                 107656.34
## Boulder Community Hospital                                           111006.80
## Longmont United Hospital                                              41145.83
## Community Medical Center Lafayette                                    96436.11
## Boulder Community Foothills Hospital                                 104796.37
## Avista Adventist Hospital                                            112929.60
## Boulder Medical Center Hospital                                      112588.19
## Boulder Medical Center                                               110684.64
## Exempla Good Samaritan Medical Center                                100764.60
## Centennial Peaks Hospital                                            112515.61
## Boulder Community Hospital Surgery Center                            111150.14
##                                            Mountain View Fire Rescue Station 4
## Boulder Community Hospital Mapleton Center                            48592.14
## Boulder County Hospital (historical)                                  42249.67
## Boulder Community Hospital                                            45232.22
## Longmont United Hospital                                              30440.44
## Community Medical Center Lafayette                                    44431.56
## Boulder Community Foothills Hospital                                  38553.89
## Avista Adventist Hospital                                             54508.42
## Boulder Medical Center Hospital                                       54528.95
## Boulder Medical Center                                                44882.27
## Exempla Good Samaritan Medical Center                                 51420.57
## Centennial Peaks Hospital                                             54519.53
## Boulder Community Hospital Surgery Center                             45338.39
##                                            Mountain View Fire Rescue Station 6
## Boulder Community Hospital Mapleton Center                            72163.12
## Boulder County Hospital (historical)                                  68092.97
## Boulder Community Hospital                                            69118.19
## Longmont United Hospital                                              56510.81
## Community Medical Center Lafayette                                    27579.95
## Boulder Community Foothills Hospital                                  56584.44
## Avista Adventist Hospital                                             46158.69
## Boulder Medical Center Hospital                                       45530.94
## Boulder Medical Center                                                68708.67
## Exempla Good Samaritan Medical Center                                 29785.11
## Centennial Peaks Hospital                                             45411.52
## Boulder Community Hospital Surgery Center                             69035.90
##                                            Pinewood Sprint Station
## Boulder Community Hospital Mapleton Center                95165.18
## Boulder County Hospital (historical)                      90315.15
## Boulder Community Hospital                                94050.20
## Longmont United Hospital                                  73800.21
## Community Medical Center Lafayette                       128108.90
## Boulder Community Foothills Hospital                     101221.89
## Avista Adventist Hospital                                132068.65
## Boulder Medical Center Hospital                          132469.52
## Boulder Medical Center                                    94099.73
## Exempla Good Samaritan Medical Center                    135420.58
## Centennial Peaks Hospital                                132527.08
## Boulder Community Hospital Surgery Center                 94386.68
##                                            Timberline Station 2
## Boulder Community Hospital Mapleton Center             51181.65
## Boulder County Hospital (historical)                   57601.67
## Boulder Community Hospital                             54549.19
## Longmont United Hospital                              125044.09
## Community Medical Center Lafayette                     96473.19
## Boulder Community Foothills Hospital                   63989.35
## Avista Adventist Hospital                              81262.57
## Boulder Medical Center Hospital                        82170.26
## Boulder Medical Center                                 54906.51
## Exempla Good Samaritan Medical Center                 100100.43
## Centennial Peaks Hospital                              82329.79
## Boulder Community Hospital Surgery Center              54455.31
##                                            City of Boulder Station 1
## Boulder Community Hospital Mapleton Center                  3685.769
## Boulder County Hospital (historical)                        5230.694
## Boulder Community Hospital                                  1419.329
## Longmont United Hospital                                   72315.516
## Community Medical Center Lafayette                         51540.985
## Boulder Community Foothills Hospital                       12578.497
## Avista Adventist Hospital                                  44316.052
## Boulder Medical Center Hospital                            45057.348
## Boulder Medical Center                                      1292.519
## Exempla Good Samaritan Medical Center                      57565.825
## Centennial Peaks Hospital                                  45179.250
## Boulder Community Hospital Surgery Center                   1092.175
##                                            City of Boulder Station 2
## Boulder Community Hospital Mapleton Center                 11110.650
## Boulder County Hospital (historical)                       14180.673
## Boulder Community Hospital                                 10763.537
## Longmont United Hospital                                   76827.336
## Community Medical Center Lafayette                         45723.654
## Boulder Community Foothills Hospital                        9922.801
## Avista Adventist Hospital                                  36200.717
## Boulder Medical Center Hospital                            36997.949
## Boulder Medical Center                                     10616.065
## Exempla Good Samaritan Medical Center                      51119.634
## Centennial Peaks Hospital                                  37130.971
## Boulder Community Hospital Surgery Center                  10429.359
##                                            City of Boulder Station 3
## Boulder Community Hospital Mapleton Center                 11335.273
## Boulder County Hospital (historical)                       11164.092
## Boulder Community Hospital                                  9240.932
## Longmont United Hospital                                   70878.649
## Community Medical Center Lafayette                         43602.027
## Boulder Community Foothills Hospital                        5016.275
## Avista Adventist Hospital                                  36511.730
## Boulder Medical Center Hospital                            37228.060
## Boulder Medical Center                                      8905.819
## Exempla Good Samaritan Medical Center                      49550.121
## Centennial Peaks Hospital                                  37345.315
## Boulder Community Hospital Surgery Center                   8994.419
##                                            City of Boulder Station 5
## Boulder Community Hospital Mapleton Center                 13189.915
## Boulder County Hospital (historical)                        6427.911
## Boulder Community Hospital                                 10510.416
## Longmont United Hospital                                   62181.120
## Community Medical Center Lafayette                         53655.704
## Boulder Community Foothills Hospital                       17107.774
## Avista Adventist Hospital                                  50283.511
## Boulder Medical Center Hospital                            50900.102
## Boulder Medical Center                                     10363.417
## Exempla Good Samaritan Medical Center                      60395.608
## Centennial Peaks Hospital                                  50998.189
## Boulder Community Hospital Surgery Center                  10788.859
##                                            City of Boulder Station 6
## Boulder Community Hospital Mapleton Center                  29635.93
## Boulder County Hospital (historical)                        23442.27
## Boulder Community Hospital                                  26267.62
## Longmont United Hospital                                    47229.46
## Community Medical Center Lafayette                          41803.91
## Boulder Community Foothills Hospital                        20664.31
## Avista Adventist Hospital                                   45137.05
## Boulder Medical Center Hospital                             45455.75
## Boulder Medical Center                                      25912.26
## Exempla Good Samaritan Medical Center                       49094.76
## Centennial Peaks Hospital                                   45499.53
## Boulder Community Hospital Surgery Center                   26365.75
##                                            City of Boulder Station 7
## Boulder Community Hospital Mapleton Center                 19424.945
## Boulder County Hospital (historical)                       18114.925
## Boulder Community Hospital                                 17089.734
## Longmont United Hospital                                   68258.975
## Community Medical Center Lafayette                         35534.583
## Boulder Community Foothills Hospital                        3621.129
## Avista Adventist Hospital                                  29776.578
## Boulder Medical Center Hospital                            30411.852
## Boulder Medical Center                                     16719.682
## Exempla Good Samaritan Medical Center                      41602.269
## Centennial Peaks Hospital                                  30514.076
## Boulder Community Hospital Surgery Center                  16882.547
##                                            Sunshine Station 1
## Boulder Community Hospital Mapleton Center           24412.16
## Boulder County Hospital (historical)                 24913.63
## Boulder Community Hospital                           25892.43
## Longmont United Hospital                             79825.70
## Community Medical Center Lafayette                   78020.99
## Boulder Community Foothills Hospital                 39222.37
## Avista Adventist Hospital                            71401.39
## Boulder Medical Center Hospital                      72158.46
## Boulder Medical Center                               26227.11
## Exempla Good Samaritan Medical Center                84353.77
## Centennial Peaks Hospital                            72283.19
## Boulder Community Hospital Surgery Center            26147.16
##                                            Lefthand Fire Station 4 - Glendale Station
## Boulder Community Hospital Mapleton Center                                   30076.71
## Boulder County Hospital (historical)                                         29097.91
## Boulder Community Hospital                                                   30930.50
## Longmont United Hospital                                                     76541.21
## Community Medical Center Lafayette                                           81682.10
## Boulder Community Foothills Hospital                                         43584.83
## Avista Adventist Hospital                                                    76505.18
## Boulder Medical Center Hospital                                              77221.16
## Boulder Medical Center                                                       31210.37
## Exempla Good Samaritan Medical Center                                        88290.06
## Centennial Peaks Hospital                                                    77337.84
## Boulder Community Hospital Surgery Center                                    31224.92
##                                            Mountain View Fire Rescue Station 9
## Boulder Community Hospital Mapleton Center                            31052.06
## Boulder County Hospital (historical)                                  35416.14
## Boulder Community Hospital                                            31730.31
## Longmont United Hospital                                              93896.57
## Community Medical Center Lafayette                                    44354.57
## Boulder Community Foothills Hospital                                  27074.82
## Avista Adventist Hospital                                             27820.00
## Boulder Medical Center Hospital                                       28722.85
## Boulder Medical Center                                                31657.94
## Exempla Good Samaritan Medical Center                                 47033.77
## Centennial Peaks Hospital                                             28882.43
## Boulder Community Hospital Surgery Center                             31392.15
##                                            Timberline Station 4
## Boulder Community Hospital Mapleton Center             70693.59
## Boulder County Hospital (historical)                   77307.29
## Boulder Community Hospital                             74017.94
## Longmont United Hospital                              145156.86
## Community Medical Center Lafayette                    111596.55
## Boulder Community Foothills Hospital                   82279.46
## Avista Adventist Hospital                              94925.90
## Boulder Medical Center Hospital                        95811.17
## Boulder Medical Center                                 74353.57
## Exempla Good Samaritan Medical Center                 114330.90
## Centennial Peaks Hospital                              95969.31
## Boulder Community Hospital Surgery Center              73892.00
##                                            Timberline Station 1
## Boulder Community Hospital Mapleton Center             38311.78
## Boulder County Hospital (historical)                   44228.15
## Boulder Community Hospital                             41669.20
## Longmont United Hospital                              110581.05
## Community Medical Center Lafayette                     88272.48
## Boulder Community Foothills Hospital                   52720.91
## Avista Adventist Hospital                              74981.30
## Boulder Medical Center Hospital                        75883.58
## Boulder Medical Center                                 42056.34
## Exempla Good Samaritan Medical Center                  92761.23
## Centennial Peaks Hospital                              76039.59
## Boulder Community Hospital Surgery Center              41634.87
##                                            Berthoud Station 2
## Boulder Community Hospital Mapleton Center          110923.85
## Boulder County Hospital (historical)                104202.67
## Boulder Community Hospital                          108252.14
## Longmont United Hospital                             45034.53
## Community Medical Center Lafayette                  116663.49
## Boulder Community Foothills Hospital                107911.01
## Avista Adventist Hospital                           128503.95
## Boulder Medical Center Hospital                     128499.51
## Boulder Medical Center                              108069.29
## Exempla Good Samaritan Medical Center               122954.08
## Centennial Peaks Hospital                           128484.82
## Boulder Community Hospital Surgery Center           108512.76
##                                            Longmont Fire Station 4
## Boulder Community Hospital Mapleton Center               84201.449
## Boulder County Hospital (historical)                     77409.611
## Boulder Community Hospital                               81014.959
## Longmont United Hospital                                  9345.765
## Community Medical Center Lafayette                       77534.631
## Boulder Community Foothills Hospital                     76604.571
## Avista Adventist Hospital                                91177.892
## Boulder Medical Center Hospital                          91040.715
## Boulder Medical Center                                   80725.234
## Exempla Good Samaritan Medical Center                    83407.312
## Centennial Peaks Hospital                                91003.222
## Boulder Community Hospital Surgery Center                81193.737
##                                            Mountain View Fire Rescue Station 10
## Boulder Community Hospital Mapleton Center                             19221.29
## Boulder County Hospital (historical)                                   26062.68
## Boulder Community Hospital                                             22379.42
## Longmont United Hospital                                               94188.15
## Community Medical Center Lafayette                                     64847.47
## Boulder Community Foothills Hospital                                   30565.76
## Avista Adventist Hospital                                              51922.24
## Boulder Medical Center Hospital                                        52815.29
## Boulder Medical Center                                                 22674.38
## Exempla Good Samaritan Medical Center                                  69373.62
## Centennial Peaks Hospital                                              52968.80
## Boulder Community Hospital Surgery Center                              22205.96
##                                            Sugar Loaf Station 3
## Boulder Community Hospital Mapleton Center             48382.92
## Boulder County Hospital (historical)                   53015.22
## Boulder Community Hospital                             51484.39
## Longmont United Hospital                              114748.25
## Community Medical Center Lafayette                    101654.57
## Boulder Community Foothills Hospital                   64129.06
## Avista Adventist Hospital                              89719.74
## Boulder Medical Center Hospital                        90607.91
## Boulder Medical Center                                 51893.58
## Exempla Good Samaritan Medical Center                 106682.62
## Centennial Peaks Hospital                              90760.15
## Boulder Community Hospital Surgery Center              51547.36
##                                            Allenspark Station 2
## Boulder Community Hospital Mapleton Center             68516.52
## Boulder County Hospital (historical)                   67193.71
## Boulder Community Hospital                             69316.56
## Longmont United Hospital                               94518.20
## Community Medical Center Lafayette                    118457.25
## Boulder Community Foothills Hospital                   81544.77
## Avista Adventist Hospital                             114730.47
## Boulder Medical Center Hospital                       115420.60
## Boulder Medical Center                                 69581.61
## Exempla Good Samaritan Medical Center                 125361.48
## Centennial Peaks Hospital                             115532.13
## Boulder Community Hospital Surgery Center              69618.09
##                                            Longmont Fire Station 3
## Boulder Community Hospital Mapleton Center                83525.89
## Boulder County Hospital (historical)                      76929.31
## Boulder Community Hospital                                80215.84
## Longmont United Hospital                                  14893.43
## Community Medical Center Lafayette                        69710.70
## Boulder Community Foothills Hospital                      74005.20
## Avista Adventist Hospital                                 84657.62
## Boulder Medical Center Hospital                           84426.61
## Boulder Medical Center                                    79888.36
## Exempla Good Samaritan Medical Center                     75093.79
## Centennial Peaks Hospital                                 84373.04
## Boulder Community Hospital Surgery Center                 80352.65
##                                            Longmont Fire Station 1
## Boulder Community Hospital Mapleton Center               77565.925
## Boulder County Hospital (historical)                     70839.549
## Boulder Community Hospital                               74321.343
## Longmont United Hospital                                  6276.205
## Community Medical Center Lafayette                       69572.136
## Boulder Community Foothills Hospital                     69259.590
## Avista Adventist Hospital                                83157.458
## Boulder Medical Center Hospital                          83017.861
## Boulder Medical Center                                   74015.590
## Exempla Good Samaritan Medical Center                    75514.507
## Centennial Peaks Hospital                                82980.036
## Boulder Community Hospital Surgery Center                74483.504
##                                            Allenspark Station 3
## Boulder Community Hospital Mapleton Center            101741.71
## Boulder County Hospital (historical)                   99945.21
## Boulder Community Hospital                            102337.26
## Longmont United Hospital                              114464.12
## Community Medical Center Lafayette                    149698.74
## Boulder Community Foothills Hospital                  114067.38
## Avista Adventist Hospital                             147365.83
## Boulder Medical Center Hospital                       148019.40
## Boulder Medical Center                                102579.82
## Exempla Good Samaritan Medical Center                 156791.18
## Centennial Peaks Hospital                             148123.85
## Boulder Community Hospital Surgery Center             102648.67
##                                            Longmont Fire Station 2
## Boulder Community Hospital Mapleton Center               73702.047
## Boulder County Hospital (historical)                     66883.237
## Boulder Community Hospital                               70556.499
## Longmont United Hospital                                  1647.459
## Community Medical Center Lafayette                       71463.180
## Boulder Community Foothills Hospital                     66794.798
## Avista Adventist Hospital                                83707.330
## Boulder Medical Center Hospital                          83651.573
## Boulder Medical Center                                   70277.673
## Exempla Good Samaritan Medical Center                    77810.093
## Centennial Peaks Hospital                                83628.284
## Boulder Community Hospital Surgery Center                70745.743
##                                            Berthoud Station 1
## Boulder Community Hospital Mapleton Center           119680.5
## Boulder County Hospital (historical)                 112833.1
## Boulder Community Hospital                           116722.0
## Longmont United Hospital                              46792.3
## Community Medical Center Lafayette                   116357.1
## Boulder Community Foothills Hospital                 114182.8
## Avista Adventist Hospital                            130337.5
## Boulder Medical Center Hospital                      130196.3
## Boulder Medical Center                               116483.8
## Exempla Good Samaritan Medical Center                121948.0
## Centennial Peaks Hospital                            130157.8
## Boulder Community Hospital Surgery Center            116945.5
##                                            Longmont Fire Station 6
## Boulder Community Hospital Mapleton Center                70738.92
## Boulder County Hospital (historical)                      64140.59
## Boulder Community Hospital                                67431.47
## Longmont United Hospital                                  11796.33
## Community Medical Center Lafayette                        60765.88
## Boulder Community Foothills Hospital                      61470.63
## Avista Adventist Hospital                                 74316.84
## Boulder Medical Center Hospital                           74170.95
## Boulder Medical Center                                    67105.22
## Exempla Good Samaritan Medical Center                     66786.61
## Centennial Peaks Hospital                                 74132.16
## Boulder Community Hospital Surgery Center                 67569.85
##                                            Allenspark Station 4
## Boulder Community Hospital Mapleton Center             115410.5
## Boulder County Hospital (historical)                   113160.7
## Boulder Community Hospital                             115783.6
## Longmont United Hospital                               120792.7
## Community Medical Center Lafayette                     161517.9
## Boulder Community Foothills Hospital                   127014.9
## Avista Adventist Hospital                              160276.4
## Boulder Medical Center Hospital                        160894.7
## Boulder Medical Center                                 116003.0
## Exempla Good Samaritan Medical Center                  168710.2
## Centennial Peaks Hospital                              160992.4
## Boulder Community Hospital Surgery Center              116103.3
##                                            Mountain View Fire Rescue Station 5
## Boulder Community Hospital Mapleton Center                           50423.762
## Boulder County Hospital (historical)                                 52059.379
## Boulder Community Hospital                                           49585.664
## Longmont United Hospital                                             93114.315
## Community Medical Center Lafayette                                   26755.789
## Boulder Community Foothills Hospital                                 38546.603
## Avista Adventist Hospital                                             9066.608
## Boulder Medical Center Hospital                                       9351.783
## Boulder Medical Center                                               49336.727
## Exempla Good Samaritan Medical Center                                25899.000
## Centennial Peaks Hospital                                             9423.310
## Boulder Community Hospital Surgery Center                            49277.879
##                                            Hygiene Station 1
## Boulder Community Hospital Mapleton Center          69242.57
## Boulder County Hospital (historical)                62412.72
## Boulder Community Hospital                          66361.63
## Longmont United Hospital                            14557.08
## Community Medical Center Lafayette                  76836.57
## Boulder Community Foothills Hospital                65128.70
## Avista Adventist Hospital                           86754.44
## Boulder Medical Center Hospital                     86833.91
## Boulder Medical Center                              66141.50
## Exempla Good Samaritan Medical Center               83666.63
## Centennial Peaks Hospital                           86834.27
## Boulder Community Hospital Surgery Center           66598.24
##                                            North Metro Fire Station 62
## Boulder Community Hospital Mapleton Center                    96387.26
## Boulder County Hospital (historical)                          96382.71
## Boulder Community Hospital                                    94829.23
## Longmont United Hospital                                     113255.61
## Community Medical Center Lafayette                            46634.59
## Boulder Community Foothills Hospital                          81906.34
## Avista Adventist Hospital                                     49434.82
## Boulder Medical Center Hospital                               48635.66
## Boulder Medical Center                                        94508.13
## Exempla Good Samaritan Medical Center                         39309.24
## Centennial Peaks Hospital                                     48503.35
## Boulder Community Hospital Surgery Center                     94564.92
##                                            North Metro Fire Station 63
## Boulder Community Hospital Mapleton Center                   102527.05
## Boulder County Hospital (historical)                         102065.66
## Boulder Community Hospital                                   100774.74
## Longmont United Hospital                                     113747.56
## Community Medical Center Lafayette                            50615.46
## Boulder Community Foothills Hospital                          87576.45
## Avista Adventist Hospital                                     55967.71
## Boulder Medical Center Hospital                               55123.81
## Boulder Medical Center                                       100437.17
## Exempla Good Samaritan Medical Center                         43443.21
## Centennial Peaks Hospital                                     54981.96
## Boulder Community Hospital Surgery Center                    100525.29
##                                            North Metro Fire Station 61
## Boulder Community Hospital Mapleton Center                    68690.25
## Boulder County Hospital (historical)                          68938.19
## Boulder Community Hospital                                    67220.47
## Longmont United Hospital                                      95313.07
## Community Medical Center Lafayette                            23789.72
## Boulder Community Foothills Hospital                          54529.35
## Avista Adventist Hospital                                     21688.22
## Boulder Medical Center Hospital                               20902.61
## Boulder Medical Center                                        66908.90
## Exempla Good Samaritan Medical Center                         17483.22
## Centennial Peaks Hospital                                     20773.81
## Boulder Community Hospital Surgery Center                     66948.80
##                                            North Metro Fire Station 64
## Boulder Community Hospital Mapleton Center                    78145.39
## Boulder County Hospital (historical)                          77181.74
## Boulder Community Hospital                                    76166.86
## Longmont United Hospital                                      91331.52
## Community Medical Center Lafayette                            25106.77
## Boulder Community Foothills Hospital                          62755.09
## Avista Adventist Hospital                                     33125.03
## Boulder Medical Center Hospital                               32221.91
## Boulder Medical Center                                        75812.53
## Exempla Good Samaritan Medical Center                         17985.26
## Centennial Peaks Hospital                                     32065.74
## Boulder Community Hospital Surgery Center                     75935.83
##                                            Timberline Station 5
## Boulder Community Hospital Mapleton Center             74941.41
## Boulder County Hospital (historical)                   81733.06
## Boulder Community Hospital                             78155.14
## Longmont United Hospital                              149903.96
## Community Medical Center Lafayette                    111203.12
## Boulder Community Foothills Hospital                   84951.15
## Avista Adventist Hospital                              93743.18
## Boulder Medical Center Hospital                        94599.10
## Boulder Medical Center                                 78456.86
## Exempla Good Samaritan Medical Center                 113269.56
## Centennial Peaks Hospital                              94753.74
## Boulder Community Hospital Surgery Center              77988.72
##                                            North Metro Fire Station 66
## Boulder Community Hospital Mapleton Center                    80748.44
## Boulder County Hospital (historical)                          78279.86
## Boulder Community Hospital                                    78203.44
## Longmont United Hospital                                      78466.76
## Community Medical Center Lafayette                            26321.60
## Boulder Community Foothills Hospital                          64669.35
## Avista Adventist Hospital                                     42074.46
## Boulder Medical Center Hospital                               41208.35
## Boulder Medical Center                                        77811.37
## Exempla Good Samaritan Medical Center                         22589.27
## Centennial Peaks Hospital                                     41052.61
## Boulder Community Hospital Surgery Center                     78035.36
##                                            Sugar Loaf Station 2
## Boulder Community Hospital Mapleton Center             18051.23
## Boulder County Hospital (historical)                   22864.01
## Boulder Community Hospital                             21129.89
## Longmont United Hospital                               88387.71
## Community Medical Center Lafayette                     72294.39
## Boulder Community Foothills Hospital                   33975.97
## Avista Adventist Hospital                              62324.33
## Boulder Medical Center Hospital                        63165.68
## Boulder Medical Center                                 21539.01
## Exempla Good Samaritan Medical Center                  77814.01
## Centennial Peaks Hospital                              63307.50
## Boulder Community Hospital Surgery Center              21192.99
##                                            Big Elk Fire Station
## Boulder Community Hospital Mapleton Center             95866.54
## Boulder County Hospital (historical)                   92071.13
## Boulder Community Hospital                             95392.78
## Longmont United Hospital                               88393.47
## Community Medical Center Lafayette                    135471.34
## Boulder Community Foothills Hospital                  104588.84
## Avista Adventist Hospital                             136998.17
## Boulder Medical Center Hospital                       137503.87
## Boulder Medical Center                                 95520.62
## Exempla Good Samaritan Medical Center                 142787.73
## Centennial Peaks Hospital                             137580.63
## Boulder Community Hospital Surgery Center              95730.01
##                                            Coal Creek Canyon FPD Station 2
## Boulder Community Hospital Mapleton Center                        43582.40
## Boulder County Hospital (historical)                              50421.84
## Boulder Community Hospital                                        46721.17
## Longmont United Hospital                                         118538.52
## Community Medical Center Lafayette                                82290.27
## Boulder Community Foothills Hospital                              53401.86
## Avista Adventist Hospital                                         66123.99
## Boulder Medical Center Hospital                                   67023.16
## Boulder Medical Center                                            47006.53
## Exempla Good Samaritan Medical Center                             85337.24
## Centennial Peaks Hospital                                         67182.54
## Boulder Community Hospital Surgery Center                         46538.08
##                                            Four Mile Lodge Station
## Boulder Community Hospital Mapleton Center                8992.493
## Boulder County Hospital (historical)                     14559.461
## Boulder Community Hospital                               12211.229
## Longmont United Hospital                                 82006.581
## Community Medical Center Lafayette                       63252.418
## Boulder Community Foothills Hospital                     24827.484
## Avista Adventist Hospital                                53927.746
## Boulder Medical Center Hospital                          54746.226
## Boulder Medical Center                                   12614.708
## Exempla Good Samaritan Medical Center                    68886.715
## Centennial Peaks Hospital                                54883.349
## Boulder Community Hospital Surgery Center                12233.721
##                                            Lefthand Fire Station 1
## Boulder Community Hospital Mapleton Center                40163.57
## Boulder County Hospital (historical)                      34753.83
## Boulder Community Hospital                                38641.75
## Longmont United Hospital                                  51846.12
## Community Medical Center Lafayette                        76369.43
## Boulder Community Foothills Hospital                      45537.76
## Avista Adventist Hospital                                 77368.01
## Boulder Medical Center Hospital                           77856.69
## Boulder Medical Center                                    38647.95
## Exempla Good Samaritan Medical Center                     83631.41
## Centennial Peaks Hospital                                 77930.68
## Boulder Community Hospital Surgery Center                 38972.25
##                                            City of Boulder Station 4
## Boulder Community Hospital Mapleton Center                  19867.27
## Boulder County Hospital (historical)                        22668.51
## Boulder Community Hospital                                  19511.64
## Longmont United Hospital                                    80565.18
## Community Medical Center Lafayette                          40128.97
## Boulder Community Foothills Hospital                        13127.44
## Avista Adventist Hospital                                   28335.80
## Boulder Medical Center Hospital                             29180.94
## Boulder Medical Center                                      19333.90
## Exempla Good Samaritan Medical Center                       44763.45
## Centennial Peaks Hospital                                   29323.84
## Boulder Community Hospital Surgery Center                   19182.18
##                                            BMFPD Station 3
## Boulder Community Hospital Mapleton Center        21442.00
## Boulder County Hospital (historical)              19674.93
## Boulder Community Hospital                        21838.22
## Longmont United Hospital                          71407.29
## Community Medical Center Lafayette                72120.76
## Boulder Community Foothills Hospital              34122.05
## Avista Adventist Hospital                         67193.07
## Boulder Medical Center Hospital                   67892.13
## Boulder Medical Center                            22083.13
## Exempla Good Samaritan Medical Center             78731.18
## Centennial Peaks Hospital                         68005.61
## Boulder Community Hospital Surgery Center         22149.77
##                                            Lefthand Fire Station 2
## Boulder Community Hospital Mapleton Center                55962.48
## Boulder County Hospital (historical)                      55314.37
## Boulder Community Hospital                                57061.29
## Longmont United Hospital                                  91416.80
## Community Medical Center Lafayette                       107630.57
## Boulder Community Foothills Hospital                      69797.32
## Avista Adventist Hospital                                102684.72
## Boulder Medical Center Hospital                          103408.98
## Boulder Medical Center                                    57355.29
## Exempla Good Samaritan Medical Center                    114343.58
## Centennial Peaks Hospital                                103527.14
## Boulder Community Hospital Surgery Center                 57346.66
##                                            Lefthand Fire Station 3
## Boulder Community Hospital Mapleton Center                30943.88
## Boulder County Hospital (historical)                      28507.30
## Boulder Community Hospital                                31092.44
## Longmont United Hospital                                  70296.60
## Community Medical Center Lafayette                        79647.12
## Boulder Community Foothills Hospital                      42667.74
## Avista Adventist Hospital                                 75944.24
## Boulder Medical Center Hospital                           76610.20
## Boulder Medical Center                                    31303.94
## Exempla Good Samaritan Medical Center                     86471.75
## Centennial Peaks Hospital                                 76717.29
## Boulder Community Hospital Surgery Center                 31415.15
##                                            Mountain View Fire Rescue Station 2
## Boulder Community Hospital Mapleton Center                            34675.40
## Boulder County Hospital (historical)                                  33054.64
## Boulder Community Hospital                                            32351.09
## Longmont United Hospital                                              67731.80
## Community Medical Center Lafayette                                    20263.10
## Boulder Community Foothills Hospital                                  18773.00
## Avista Adventist Hospital                                             18379.31
## Boulder Medical Center Hospital                                       18689.11
## Boulder Medical Center                                                31975.92
## Exempla Good Samaritan Medical Center                                 26426.26
## Centennial Peaks Hospital                                             18733.74
## Boulder Community Hospital Surgery Center                             32150.34
##                                            Timberline Station 6
## Boulder Community Hospital Mapleton Center             81784.77
## Boulder County Hospital (historical)                   88590.30
## Boulder Community Hospital                             84979.77
## Longmont United Hospital                              156761.58
## Community Medical Center Lafayette                    116790.25
## Boulder Community Foothills Hospital                   91507.18
## Avista Adventist Hospital                              99074.58
## Boulder Medical Center Hospital                        99915.30
## Boulder Medical Center                                 85276.49
## Exempla Good Samaritan Medical Center                 118589.23
## Centennial Peaks Hospital                             100067.93
## Boulder Community Hospital Surgery Center              84808.09
##                                            Longmont Fire Station 5
## Boulder Community Hospital Mapleton Center                61689.01
## Boulder County Hospital (historical)                      54898.96
## Boulder Community Hospital                                58505.67
## Longmont United Hospital                                  13353.41
## Community Medical Center Lafayette                        61838.15
## Boulder Community Foothills Hospital                      54591.24
## Avista Adventist Hospital                                 72763.16
## Boulder Medical Center Hospital                           72771.36
## Boulder Medical Center                                    58217.73
## Exempla Good Samaritan Medical Center                     68552.68
## Centennial Peaks Hospital                                 72759.39
## Boulder Community Hospital Surgery Center                 58686.21
##                                            North Metro Fire Station 67
## Boulder Community Hospital Mapleton Center                   53231.786
## Boulder County Hospital (historical)                         53301.387
## Boulder Community Hospital                                   51657.791
## Longmont United Hospital                                     84627.015
## Community Medical Center Lafayette                           15014.384
## Boulder Community Foothills Hospital                         38879.180
## Avista Adventist Hospital                                     6831.656
## Boulder Medical Center Hospital                               5928.750
## Boulder Medical Center                                       51338.933
## Exempla Good Samaritan Medical Center                        13755.803
## Centennial Peaks Hospital                                     5772.979
## Boulder Community Hospital Surgery Center                    51392.066
##                                            Coal Creek Canyon FPD Station 3
## Boulder Community Hospital Mapleton Center                        54140.40
## Boulder County Hospital (historical)                              59756.86
## Boulder Community Hospital                                        55741.12
## Longmont United Hospital                                         120297.47
## Community Medical Center Lafayette                                64103.46
## Boulder Community Foothills Hospital                              53404.73
## Avista Adventist Hospital                                         45480.46
## Boulder Medical Center Hospital                                   46190.05
## Boulder Medical Center                                            55776.18
## Exempla Good Samaritan Medical Center                             64274.50
## Centennial Peaks Hospital                                         46323.85
## Boulder Community Hospital Surgery Center                         55418.92
##                                            North Metro Fire Training Center
## Boulder Community Hospital Mapleton Center                         95736.79
## Boulder County Hospital (historical)                               92419.57
## Boulder Community Hospital                                         92920.70
## Longmont United Hospital                                           78425.98
## Community Medical Center Lafayette                                 43438.55
## Boulder Community Foothills Hospital                               79712.97
## Avista Adventist Hospital                                          60435.45
## Boulder Medical Center Hospital                                    59592.91
## Boulder Medical Center                                             92516.11
## Exempla Good Samaritan Medical Center                              40920.58
## Centennial Peaks Hospital                                          59440.28
## Boulder Community Hospital Surgery Center                          92794.16
##                                            Timberline Station 9
## Boulder Community Hospital Mapleton Center             89385.27
## Boulder County Hospital (historical)                   96212.63
## Boulder Community Hospital                             92285.02
## Longmont United Hospital                              163569.85
## Community Medical Center Lafayette                    115587.24
## Boulder Community Foothills Hospital                   96257.19
## Avista Adventist Hospital                              97110.86
## Boulder Medical Center Hospital                        97867.16
## Boulder Medical Center                                 92518.04
## Exempla Good Samaritan Medical Center                 116180.73
## Centennial Peaks Hospital                              98007.71
## Boulder Community Hospital Surgery Center              92057.41
##                                            North Metro Fire Station 65
## Boulder Community Hospital Mapleton Center                    64886.26
## Boulder County Hospital (historical)                          65806.08
## Boulder Community Hospital                                    63722.30
## Longmont United Hospital                                      97868.34
## Community Medical Center Lafayette                            26450.65
## Boulder Community Foothills Hospital                          51669.96
## Avista Adventist Hospital                                     18399.49
## Boulder Medical Center Hospital                               17814.95
## Boulder Medical Center                                        63439.12
## Exempla Good Samaritan Medical Center                         21541.94
## Centennial Peaks Hospital                                     17726.96
## Boulder Community Hospital Surgery Center                     63431.69
##                                            Boulder Rural Station 2
## Boulder Community Hospital Mapleton Center                31565.90
## Boulder County Hospital (historical)                      25001.49
## Boulder Community Hospital                                29104.66
## Longmont United Hospital                                  46898.34
## Community Medical Center Lafayette                        61334.69
## Boulder Community Foothills Hospital                      32580.92
## Avista Adventist Hospital                                 63030.42
## Boulder Medical Center Hospital                           63469.10
## Boulder Medical Center                                    28971.05
## Exempla Good Samaritan Medical Center                     68605.59
## Centennial Peaks Hospital                                 63534.12
## Boulder Community Hospital Surgery Center                 29390.65
##                                            Indian Peaks Station 2
## Boulder Community Hospital Mapleton Center               57927.71
## Boulder County Hospital (historical)                     58330.46
## Boulder Community Hospital                               59500.25
## Longmont United Hospital                                 99587.16
## Community Medical Center Lafayette                      111322.70
## Boulder Community Foothills Hospital                     72757.71
## Avista Adventist Hospital                               104949.53
## Boulder Medical Center Hospital                         105717.49
## Boulder Medical Center                                   59833.48
## Exempla Good Samaritan Medical Center                   117799.95
## Centennial Peaks Hospital                               105844.23
## Boulder Community Hospital Surgery Center                59755.25
##                                            Timberline Station 7
## Boulder Community Hospital Mapleton Center             84559.63
## Boulder County Hospital (historical)                   91373.40
## Boulder Community Hospital                             87741.97
## Longmont United Hospital                              159539.90
## Community Medical Center Lafayette                    118910.90
## Boulder Community Foothills Hospital                   94113.85
## Avista Adventist Hospital                             101087.35
## Boulder Medical Center Hospital                       101920.52
## Boulder Medical Center                                 88035.45
## Exempla Good Samaritan Medical Center                 120584.75
## Centennial Peaks Hospital                             102072.14
## Boulder Community Hospital Surgery Center              87566.97
##                                            Mountain View Fire Rescue Station 8
## Boulder Community Hospital Mapleton Center                            72143.23
## Boulder County Hospital (historical)                                  69177.90
## Boulder Community Hospital                                            69424.49
## Longmont United Hospital                                              68727.97
## Community Medical Center Lafayette                                    19927.14
## Boulder Community Foothills Hospital                                  56063.76
## Avista Adventist Hospital                                             37955.35
## Boulder Medical Center Hospital                                       37184.36
## Boulder Medical Center                                                69024.02
## Exempla Good Samaritan Medical Center                                 19203.40
## Centennial Peaks Hospital                                             37042.38
## Boulder Community Hospital Surgery Center                             69281.15
##                                            Mountain View Fire Rescue Station 1
## Boulder Community Hospital Mapleton Center                            91998.87
## Boulder County Hospital (historical)                                  85801.24
## Boulder Community Hospital                                            88623.52
## Longmont United Hospital                                              31190.26
## Community Medical Center Lafayette                                    67458.24
## Boulder Community Foothills Hospital                                  80312.51
## Avista Adventist Hospital                                             84450.31
## Boulder Medical Center Hospital                                       84052.61
## Boulder Medical Center                                                88259.31
## Exempla Good Samaritan Medical Center                                 71567.81
## Centennial Peaks Hospital                                             83970.75
## Boulder Community Hospital Surgery Center                             88706.41
##                                            Mountain View Fire Rescue Station 7
## Boulder Community Hospital Mapleton Center                            99252.10
## Boulder County Hospital (historical)                                  94672.06
## Boulder Community Hospital                                            96091.18
## Longmont United Hospital                                              64262.91
## Community Medical Center Lafayette                                    54250.66
## Boulder Community Foothills Hospital                                  84053.89
## Avista Adventist Hospital                                             72806.85
## Boulder Medical Center Hospital                                       72087.22
## Boulder Medical Center                                                95682.66
## Exempla Good Samaritan Medical Center                                 54460.00
## Centennial Peaks Hospital                                             71952.87
## Boulder Community Hospital Surgery Center                             96039.12
##                                            Lafayette Fire Department Station 2
## Boulder Community Hospital Mapleton Center                           61497.557
## Boulder County Hospital (historical)                                 60042.300
## Boulder Community Hospital                                           59304.834
## Longmont United Hospital                                             77496.918
## Community Medical Center Lafayette                                    7489.290
## Boulder Community Foothills Hospital                                 45757.150
## Avista Adventist Hospital                                            20527.492
## Boulder Medical Center Hospital                                      19680.726
## Boulder Medical Center                                               58935.757
## Exempla Good Samaritan Medical Center                                 1024.461
## Centennial Peaks Hospital                                            19527.793
## Boulder Community Hospital Surgery Center                            59093.705
##                                            Louisville Station 3
## Boulder Community Hospital Mapleton Center            55508.813
## Boulder County Hospital (historical)                  54743.720
## Boulder Community Hospital                            53581.973
## Longmont United Hospital                              79914.913
## Community Medical Center Lafayette                     8706.370
## Boulder Community Foothills Hospital                  40265.176
## Avista Adventist Hospital                             12362.332
## Boulder Medical Center Hospital                       11508.359
## Boulder Medical Center                                53233.365
## Exempla Good Samaritan Medical Center                  7168.943
## Centennial Peaks Hospital                             11354.684
## Boulder Community Hospital Surgery Center             53344.608
##                                            Allenspark Station 5
## Boulder Community Hospital Mapleton Center             73766.69
## Boulder County Hospital (historical)                   72164.29
## Boulder Community Hospital                             74437.02
## Longmont United Hospital                               95712.34
## Community Medical Center Lafayette                    122848.50
## Boulder Community Foothills Hospital                   86415.99
## Avista Adventist Hospital                             119674.99
## Boulder Medical Center Hospital                       120348.58
## Boulder Medical Center                                 74689.08
## Exempla Good Samaritan Medical Center                 129826.56
## Centennial Peaks Hospital                             120456.93
## Boulder Community Hospital Surgery Center              74744.55
##                                            City of Boulder Station 8
## Boulder Community Hospital Mapleton Center                  28329.77
## Boulder County Hospital (historical)                        21935.40
## Boulder Community Hospital                                  24988.46
## Longmont United Hospital                                    47667.60
## Community Medical Center Lafayette                          43941.39
## Boulder Community Foothills Hospital                        20632.81
## Avista Adventist Hospital                                   46675.58
## Boulder Medical Center Hospital                             47027.08
## Boulder Medical Center                                      24650.20
## Exempla Good Samaritan Medical Center                       51213.67
## Centennial Peaks Hospital                                   47076.71
## Boulder Community Hospital Surgery Center                   25111.55
##                                            Timberline Station 3
## Boulder Community Hospital Mapleton Center             70834.21
## Boulder County Hospital (historical)                   77062.90
## Boulder Community Hospital                             74211.48
## Longmont United Hospital                              143699.73
## Community Medical Center Lafayette                    116245.98
## Boulder Community Foothills Hospital                   84040.12
## Avista Adventist Hospital                             100540.97
## Boulder Medical Center Hospital                       101443.65
## Boulder Medical Center                                 74580.99
## Exempla Good Samaritan Medical Center                 119622.90
## Centennial Peaks Hospital                             101603.22
## Boulder Community Hospital Surgery Center              74138.79
##                                            Timberline Station 8
## Boulder Community Hospital Mapleton Center             79846.68
## Boulder County Hospital (historical)                   86631.94
## Boulder Community Hospital                             82646.87
## Longmont United Hospital                              153573.95
## Community Medical Center Lafayette                    104907.30
## Boulder Community Foothills Hospital                   86046.44
## Avista Adventist Hospital                              86445.45
## Boulder Medical Center Hospital                        87205.78
## Boulder Medical Center                                 82861.84
## Exempla Good Samaritan Medical Center                 105553.17
## Centennial Peaks Hospital                              87346.95
## Boulder Community Hospital Surgery Center              82406.34
##                                            Timberline Station 10
## Boulder Community Hospital Mapleton Center              96769.51
## Boulder County Hospital (historical)                   103530.56
## Boulder Community Hospital                             100010.95
## Longmont United Hospital                               171672.02
## Community Medical Center Lafayette                     132220.57
## Boulder Community Foothills Hospital                   106921.13
## Avista Adventist Hospital                              114387.60
## Boulder Medical Center Hospital                        115218.95
## Boulder Medical Center                                 100319.65
## Exempla Good Samaritan Medical Center                  133879.46
## Centennial Peaks Hospital                              115370.31
## Boulder Community Hospital Surgery Center               99852.12
##                                            Sunshine Station 2
## Boulder Community Hospital Mapleton Center           24262.54
## Boulder County Hospital (historical)                 24927.84
## Boulder Community Hospital                           25813.04
## Longmont United Hospital                             80311.03
## Community Medical Center Lafayette                   78029.19
## Boulder Community Foothills Hospital                 39190.05
## Avista Adventist Hospital                            71271.57
## Boulder Medical Center Hospital                      72032.70
## Boulder Medical Center                               26153.00
## Exempla Good Samaritan Medical Center                84334.75
## Centennial Peaks Hospital                            72158.22
## Boulder Community Hospital Surgery Center            26062.66
##                                            Four Mile Poorman Station
## Boulder Community Hospital Mapleton Center                  13753.05
## Boulder County Hospital (historical)                        17024.59
## Boulder Community Hospital                                  16239.97
## Longmont United Hospital                                    81301.32
## Community Medical Center Lafayette                          68680.67
## Boulder Community Foothills Hospital                        29753.48
## Avista Adventist Hospital                                   60323.54
## Boulder Medical Center Hospital                             61121.70
## Boulder Medical Center                                      16638.94
## Exempla Good Samaritan Medical Center                       74590.69
## Centennial Peaks Hospital                                   61254.66
## Boulder Community Hospital Surgery Center                   16393.01
boulder_hospital_firstation_distancematrix["Boulder Medical Center", "Nederland Station 2"]
## 53613.37 [US_survey_foot]
boulder_hospital_firstation_distancematrix_df<-as.data.frame(boulder_hospital_firstation_distancematrix)
# distance to closest fire station for each hospital
apply(boulder_hospital_firstation_distancematrix_df, 1, FUN=min)
## Boulder Community Hospital Mapleton Center 
##                                   3685.769 
##       Boulder County Hospital (historical) 
##                                   5230.694 
##                 Boulder Community Hospital 
##                                   1419.329 
##                   Longmont United Hospital 
##                                   1647.459 
##         Community Medical Center Lafayette 
##                                   6032.733 
##       Boulder Community Foothills Hospital 
##                                   3621.129 
##                  Avista Adventist Hospital 
##                                   6831.656 
##            Boulder Medical Center Hospital 
##                                   5928.750 
##                     Boulder Medical Center 
##                                   1292.519 
##      Exempla Good Samaritan Medical Center 
##                                   1024.461 
##                  Centennial Peaks Hospital 
##                                   5772.979 
##  Boulder Community Hospital Surgery Center 
##                                   1092.175
# distance to closest hospital for each fire station
apply(boulder_hospital_firstation_distancematrix_df, 2, FUN=min)
##                       Sugar Loaf Station 1 
##                                  31083.708 
##                        Nederland Station 3 
##                                  81775.102 
##                        Nederland Station 2 
##                                  49935.004 
##                        Nederland Station 1 
##                                  65913.011 
##                       Allenspark Station 1 
##                                  90547.067 
##                    Boulder Rural Station 1 
##                                  21240.541 
##                            BMFPD Station 1 
##                                   9728.971 
##                            BMFPD Station 2 
##                                  25692.910 
##            Coal Creek Canyon FPD Station 1 
##                                  44629.031 
##            Coal Creek Canyon FPD Station 4 
##                                  58921.029 
##               Four Mile Logan Mill Station 
##                                  21401.810 
##                   Four Mile Salina Station 
##                                  26442.855 
##              Four Mile Wall Street Station 
##                                  26286.468 
##         Gold Hill Fire Protection District 
##                                  36796.930 
##                     Indian Peaks Station 1 
##                                  62658.254 
##        Lafayette Fire Department Station 1 
##                                   6032.733 
##                        Jamestown Fire Hall 
##                                  41061.996 
##                       Louisville Station 1 
##                                   8381.618 
##                       Louisville Station 2 
##                                   8602.903 
##                            Lyons Station 1 
##                                  41955.153 
##                            Lyons Station 2 
##                                  57437.745 
##       Mountain View Fire Rescue Station 13 
##                                  24999.680 
##        Mountain View Fire Rescue Station 3 
##                                  41145.826 
##        Mountain View Fire Rescue Station 4 
##                                  30440.445 
##        Mountain View Fire Rescue Station 6 
##                                  27579.953 
##                    Pinewood Sprint Station 
##                                  73800.213 
##                       Timberline Station 2 
##                                  51181.654 
##                  City of Boulder Station 1 
##                                   1092.175 
##                  City of Boulder Station 2 
##                                   9922.801 
##                  City of Boulder Station 3 
##                                   5016.275 
##                  City of Boulder Station 5 
##                                   6427.911 
##                  City of Boulder Station 6 
##                                  20664.307 
##                  City of Boulder Station 7 
##                                   3621.129 
##                         Sunshine Station 1 
##                                  24412.158 
## Lefthand Fire Station 4 - Glendale Station 
##                                  29097.909 
##        Mountain View Fire Rescue Station 9 
##                                  27074.822 
##                       Timberline Station 4 
##                                  70693.586 
##                       Timberline Station 1 
##                                  38311.778 
##                         Berthoud Station 2 
##                                  45034.531 
##                    Longmont Fire Station 4 
##                                   9345.765 
##       Mountain View Fire Rescue Station 10 
##                                  19221.286 
##                       Sugar Loaf Station 3 
##                                  48382.923 
##                       Allenspark Station 2 
##                                  67193.708 
##                    Longmont Fire Station 3 
##                                  14893.432 
##                    Longmont Fire Station 1 
##                                   6276.205 
##                       Allenspark Station 3 
##                                  99945.214 
##                    Longmont Fire Station 2 
##                                   1647.459 
##                         Berthoud Station 1 
##                                  46792.301 
##                    Longmont Fire Station 6 
##                                  11796.329 
##                       Allenspark Station 4 
##                                 113160.703 
##        Mountain View Fire Rescue Station 5 
##                                   9066.608 
##                          Hygiene Station 1 
##                                  14557.085 
##                North Metro Fire Station 62 
##                                  39309.243 
##                North Metro Fire Station 63 
##                                  43443.207 
##                North Metro Fire Station 61 
##                                  17483.220 
##                North Metro Fire Station 64 
##                                  17985.257 
##                       Timberline Station 5 
##                                  74941.406 
##                North Metro Fire Station 66 
##                                  22589.269 
##                       Sugar Loaf Station 2 
##                                  18051.233 
##                       Big Elk Fire Station 
##                                  88393.471 
##            Coal Creek Canyon FPD Station 2 
##                                  43582.404 
##                    Four Mile Lodge Station 
##                                   8992.493 
##                    Lefthand Fire Station 1 
##                                  34753.826 
##                  City of Boulder Station 4 
##                                  13127.436 
##                            BMFPD Station 3 
##                                  19674.928 
##                    Lefthand Fire Station 2 
##                                  55314.371 
##                    Lefthand Fire Station 3 
##                                  28507.298 
##        Mountain View Fire Rescue Station 2 
##                                  18379.309 
##                       Timberline Station 6 
##                                  81784.774 
##                    Longmont Fire Station 5 
##                                  13353.406 
##                North Metro Fire Station 67 
##                                   5772.979 
##            Coal Creek Canyon FPD Station 3 
##                                  45480.465 
##           North Metro Fire Training Center 
##                                  40920.583 
##                       Timberline Station 9 
##                                  89385.271 
##                North Metro Fire Station 65 
##                                  17726.963 
##                    Boulder Rural Station 2 
##                                  25001.491 
##                     Indian Peaks Station 2 
##                                  57927.713 
##                       Timberline Station 7 
##                                  84559.627 
##        Mountain View Fire Rescue Station 8 
##                                  19203.400 
##        Mountain View Fire Rescue Station 1 
##                                  31190.257 
##        Mountain View Fire Rescue Station 7 
##                                  54250.661 
##        Lafayette Fire Department Station 2 
##                                   1024.461 
##                       Louisville Station 3 
##                                   7168.943 
##                       Allenspark Station 5 
##                                  72164.292 
##                  City of Boulder Station 8 
##                                  20632.808 
##                       Timberline Station 3 
##                                  70834.205 
##                       Timberline Station 8 
##                                  79846.682 
##                      Timberline Station 10 
##                                  96769.505 
##                         Sunshine Station 2 
##                                  24262.541 
##                  Four Mile Poorman Station 
##                                  13753.049

6.4 Extracting areas

# extracts area of Boulder county
boulder_area<-st_area(boulder_county_projected)
boulder_area
## 20637967089 [US_survey_foot^2]
boulder_area_km<-set_units(boulder_area, "km^2")
CO_tracts<-get_decennial(geography = "tract",
                           state="CO",
                           variables = "P001001",
                           year = 2010,
                           geometry=TRUE) %>% 
                      st_transform(2231)
## Getting data from the 2010 decennial Census
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using Census Summary File 1
## 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |=======                                                               |  10%
  |                                                                            
  |===========                                                           |  16%
  |                                                                            
  |=============                                                         |  18%
  |                                                                            
  |=================                                                     |  25%
  |                                                                            
  |=====================                                                 |  30%
  |                                                                            
  |==========================                                            |  36%
  |                                                                            
  |==============================                                        |  42%
  |                                                                            
  |=======================================                               |  56%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |==============================================                        |  66%
  |                                                                            
  |==================================================                    |  72%
  |                                                                            
  |=======================================================               |  78%
  |                                                                            
  |===========================================================           |  84%
  |                                                                            
  |===============================================================       |  90%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |======================================================================| 100%
tm_shape(CO_tracts)+
  tm_polygons()

boulder_tracts<-CO_tracts %>% 
                  st_filter(boulder_county_projected, .predicate=st_intersects)
tm_shape(boulder_tracts)+
  tm_polygons()+
tm_shape(boulder_county_projected)+
  tm_polygons("red", alpha=0.5)

boulder_tracts
## Simple feature collection with 90 features and 4 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 2820001 ymin: 1145863 xmax: 3172998 ymax: 1452430
## projected CRS:  NAD83 / Colorado North (ftUS)
## # A tibble: 90 × 5
##    GEOID       NAME                     variable value                  geometry
##  * <chr>       <chr>                    <chr>    <dbl> <MULTIPOLYGON [US_survey>
##  1 08013012102 Census Tract 121.02, Bo… P001001   6466 (((3067656 1253540, 3067…
##  2 08013012202 Census Tract 122.02, Bo… P001001   5847 (((3067622 1247030, 3067…
##  3 08013012507 Census Tract 125.07, Bo… P001001   4202 (((3072970 1237803, 3072…
##  4 08013012605 Census Tract 126.05, Bo… P001001   1529 (((3071075 1245607, 3070…
##  5 08013012709 Census Tract 127.09, Bo… P001001   1811 (((3089986 1267510, 3089…
##  6 08013012905 Census Tract 129.05, Bo… P001001   2481 (((3112542 1243181, 3113…
##  7 08013013201 Census Tract 132.01, Bo… P001001   1531 (((3124221 1327955, 3124…
##  8 08013013202 Census Tract 132.02, Bo… P001001   1375 (((3081979 1285295, 3081…
##  9 08013013205 Census Tract 132.05, Bo… P001001   5078 (((3100975 1291790, 3101…
## 10 08013013213 Census Tract 132.13, Bo… P001001   7271 (((3094846 1285135, 3092…
## # … with 80 more rows
# Turn off scientific notation
options(scipen = 100)

boulder_tract_areas<-boulder_tracts %>% 
                      mutate(area=st_area(boulder_tracts))
units(boulder_tract_areas$area)<-"km^2"
boulder_tract_areas
## Simple feature collection with 90 features and 5 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: 2820001 ymin: 1145863 xmax: 3172998 ymax: 1452430
## projected CRS:  NAD83 / Colorado North (ftUS)
## # A tibble: 90 × 6
##    GEOID       NAME               variable value                  geometry  area
##  * <chr>       <chr>              <chr>    <dbl> <MULTIPOLYGON [US_survey> [km^…
##  1 08013012102 Census Tract 121.… P001001   6466 (((3067656 1253540, 3067…  2.88
##  2 08013012202 Census Tract 122.… P001001   5847 (((3067622 1247030, 3067…  1.64
##  3 08013012507 Census Tract 125.… P001001   4202 (((3072970 1237803, 3072…  1.64
##  4 08013012605 Census Tract 126.… P001001   1529 (((3071075 1245607, 3070…  1.23
##  5 08013012709 Census Tract 127.… P001001   1811 (((3089986 1267510, 3089…  9.86
##  6 08013012905 Census Tract 129.… P001001   2481 (((3112542 1243181, 3113…  1.34
##  7 08013013201 Census Tract 132.… P001001   1531 (((3124221 1327955, 3124… 62.4 
##  8 08013013202 Census Tract 132.… P001001   1375 (((3081979 1285295, 3081… 65.6 
##  9 08013013205 Census Tract 132.… P001001   5078 (((3100975 1291790, 3101… 22.9 
## 10 08013013213 Census Tract 132.… P001001   7271 (((3094846 1285135, 3092… 20.6 
## # … with 80 more rows

7 Distance Buffers

https://geodacenter.github.io/opioid-environment-toolkit/buffer_analysis.html

firestations_hospitals

hospital_buffers<-st_buffer(boulder_hospitals, dist=5280)
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(boulder_hospitals)+
  tm_dots("blue")+
tm_shape(hospital_buffers)+
  tm_borders(alpha=0.5, "blue", lwd=3)

fire_station_buffers<-st_buffer(boulder_fire_stations_projected, dist=5280)
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(boulder_fire_stations_projected)+
  tm_dots("red")+
tm_shape(fire_station_buffers)+
  tm_borders(alpha=0.5, "red", lwd=3)

tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(boulder_fire_stations_projected)+
  tm_dots("red")+
tm_shape(fire_station_buffers)+
  tm_borders(alpha=0.5, "red", lwd=3)+
tm_shape(boulder_hospitals)+
  tm_dots("blue")+
tm_shape(hospital_buffers)+
  tm_borders(alpha=0.5, "blue", lwd=3)

hospital_firestation_intersection<-st_intersection(hospital_buffers, fire_station_buffers)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(hospital_firestation_intersection)+
  tm_polygons("orange")

hospital_firestation_intersection_dissolve<-hospital_firestation_intersection %>% 
                                            group_by() %>% 
                                            summarise()
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(hospital_firestation_intersection_dissolve)+
  tm_polygons("orange")

fire_hospital_intersection_area<-st_area(hospital_firestation_intersection_dissolve)
fire_hospital_intersection_area
## 441571996 [US_survey_foot^2]
fire_hospital_intersection_area_sqmiles<-set_units(fire_hospital_intersection_area, "miles^2")

fire_hospital_intersection_area_sqmiles
## 15.83928 [miles^2]

15.83 sq miles within Boulder County is within 1 mile of both a fire station AND a hospital

hospital_firestation_union<-st_union(hospital_buffers, fire_station_buffers)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(hospital_firestation_union)+
  tm_polygons("gold")

hospital_firestation_union_dissolve<-hospital_firestation_union %>% 
                                            group_by() %>% 
                                            summarise()
tm_shape(boulder_county_projected)+
  tm_polygons()+
tm_shape(hospital_firestation_union_dissolve)+
  tm_polygons("gold")

hospital_firestation_union_area<-st_area(hospital_firestation_union_dissolve)

hospital_firestation_union_area
## 7184464841 [US_survey_foot^2]
hospital_firestation_union_area_sqmiles<-set_units(hospital_firestation_union_area, "miles^2")

hospital_firestation_union_area_sqmiles
## 257.7082 [miles^2]

257 miles are within 1 mile of a fire station OR hospital

7.1 Merging shapefiles together

CO_tracts_test<-get_decennial(geography = "tract",
                           state="CO",
                           variables = "P001001",
                           year = 2010,
                           geometry=TRUE) %>% 
                      st_transform(4326)
## Getting data from the 2010 decennial Census
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using Census Summary File 1
nm_counties<-get_decennial(geography = "county",
                           state="NM",
                           variables = "P001001",
                           year = 2010,
                           geometry=TRUE) %>% 
                      st_transform(4326)
## Getting data from the 2010 decennial Census
## Downloading feature geometry from the Census website.  To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
## Using Census Summary File 1
kk<-rbind(CO_tracts_test, nm_counties)
tm_shape(kk)+
  tm_polygons()

continental_usa_dissolve<-continental_USA_regions_projected %>% group_by(region) %>% summarise()

https://geobgu.xyz/r/geometric-operations-with-vector-layers.html#distance

https://towardsdatascience.com/breaking-down-geocoding-in-r-a-complete-guide-1d0f8acd0d4b https://cran.r-project.org/web/packages/tidygeocoder/vignettes/tidygeocoder.html

https://www.epa.gov/frs/epa-frs-facilities-state-single-file-csv-download https://www.epa.gov/frs/geospatial-data-download-service

geocoding buffer spatial join intersect/union/overlap distance calculations area calculations coordinate systems

https://www.epa.gov/frs/epa-frs-facilities-state-single-file-csv-download

latlong: https://www.britannica.com/science/latitude

https://philmikejones.me/tutorials/2015-09-03-dissolve-polygons-in-r.html

https://geobgu.xyz/r/geometric-operations-with-vector-layers.html

https://github.com/r-spatial/sf/issues/290

https://mgimond.github.io/Spatial/vector-operations-in-r.html

http://learnline.cdu.edu.au/units/ses101/env208/w5_files/GeoprocessingTools_handouts.pdf

https://www.r-bloggers.com/2014/07/clipping-spatial-data-in-r/

superfund dataset: https://dataverse.unc.edu/dataset.xhtml?persistentId=doi:10.15139/S3/4QEIGO

https://glenbambrick.com/tag/map-projections/

https://walker-data.com/census-r/spatial-analysis-with-us-census-data.html

https://stackoverflow.com/questions/62442150/why-use-st-intersection-rather-than-st-intersects

http://www.wvview.org/spatial_analytics/Visualizing_Spatial_Data/_site/Visualize_Spatial_Data.html

https://datacornering.com/remove-scientific-notation-in-r/